Posted By

brownrl on 06/27/11


Tagged

forms elements checkbox on


Versions (?)

PHP getCheckBox


 / Published in: PHP
 

URL: http://www.itsgotto.be/cv.php

Simple simple simple function to make a checkbox for a form. Retains checked status.

  1. <?php
  2.  
  3. // Function Get Check Box
  4. //
  5. // Make a simple checkbox for a form
  6. //
  7. // $name -> the name and id of the html checkBox
  8. // $style -> optional styling to add in to the check box
  9. //
  10. // works with _POST, if the box was checked it will remain checked on repost or reload
  11. //
  12. function getCheckBox( $name , $style = "" )
  13. {
  14. $_POST[$name] = strtolower( $_POST[$name] );
  15. $on = ( $_POST[$name] == "on" ) ? " checked " : ""; // this is done cause some browsers... like to use 'On' instead of 'on'
  16. if( strlen( $style ) )
  17. {
  18. $style = "style=\"".$style."\"";
  19. }
  20.  
  21.  
  22. return "<input ".$style." type=\"checkbox\" id=\"".$name."\" name=\"".$name."\"".$on."/>";
  23. }
  24.  
  25. ?>

Report this snippet  

You need to login to post a comment.