morpe

php + Checkbox

May 11th, 2011
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. <h1>come usare php e i check box</h1>
  2. <form name='tag' method='post' action='php_e_checkbox.php'>
  3.     <b>che frutta ti piace?</b><br>
  4.     <input type='checkbox' name='frutta[]' value='mela' />mela<br>
  5.     <input type='checkbox' name='frutta[]' value='pera' />pera<br>
  6.     <input type='checkbox' name='frutta[]' value='fragola' />fragola<br>
  7.     <input type='checkbox' name='frutta[]' value='banana' />banana<br>
  8.     <input type='submit' value='invia'>
  9. </form>
  10. <br>
  11. <a href='php_e_checkbox.php'>back</a><br>
  12.  
  13. <?php
  14. $out ="";
  15.  
  16. if( isset($_POST['frutta']) )
  17. {
  18.     $tags = $_POST['frutta'];
  19.     foreach( $tags as $v)
  20.     {                                                                                
  21.         $out .= "$v, ";
  22.     }
  23.     echo "hai selezionato: <b>$out</b>";
  24. }  
  25.  
  26. $info =  "<code>".htmlentities("<input type='checkbox' name='frutta[]' value='banana' />banana<br>")."</code>";
  27. echo "
  28. <h2>importante</h2>
  29. $info<br>
  30. <br>la proprieta' <code>name='tag[]'</code> senza le parentesi quadre non permetterebbe il passaggio di dati multipli, quindi restituisce un Array.
  31. ";
  32.  
  33. ?>
  34.  
  35. <br><br><img src='img/cupeicbm.png' title='come usare php e i check box' width='800'/>
Advertisement
Add Comment
Please, Sign In to add comment