Posted By

brownrl on 07/27/09


Tagged

forms radio no yes


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


PHP getYesNo


 / Published in: PHP
 

URL: http://www.goingson.be

Small function so that I can quickly create Yes and No form radio tickers... 0 and 1, it stores better in the DB.

  1. // Function: getYesNo
  2. //
  3. // Easy Peasy function to make quick yes/no radio sets for forms.
  4. //
  5. //
  6. // $name -> the name of the radio group
  7. //
  8. function getYesNo( $name )
  9. {
  10. $temp .= "<input type=\"radio\" name=\"".$name."\" value=\"1\" ";
  11. if( $_POST[$name] >= 1 )
  12. {
  13. $temp .= "CHECKED";
  14. }
  15.  
  16. $temp .= " />&nbsp;" . "yes" . "\n";
  17. $temp .= "&nbsp;&nbsp;&nbsp;&nbsp;";
  18. $temp .= "<input type=\"radio\" name=\"".$name."\" value=\"0\" ";
  19.  
  20. if( intval( $_POST[$name] ) == "0" )
  21. {
  22. $temp .= "CHECKED";
  23. }
  24.  
  25. $temp .= " />";
  26. $temp .= "&nbsp;" . "no" . "\n";
  27.  
  28. return $temp;
  29. }

Report this snippet  

You need to login to post a comment.