PHP getCheckBox


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.