kiki Posted June 28, 2008 Share Posted June 28, 2008 hello i have question and i really hope someone can help me please. so i made a form with like lets say 3 options: red value=1 blue value=2 green value=3 and each of the options has a value set to it. but lets say i needed to process it but how do i set the commands that will allow me to send the value of the selected option? like im using a gateway but lets say if the person chose red for example and the value is one i need to make it so the selected value will be sent to the gateway. usually i just use like $red or something but now its different with 3 different choices... can someone please help me with this please? here is the form: <form action="youtwo.php" method="post"> <table> <tr><td>Name:</td> <td><input type="text" name="business" size="27"> </td> </tr> <tr> <td>Email: </td> <td> <input type="text" name="email" size="27"> </td> </tr> <tr> <td>I would like to be: </td> <td> <input type="radio" name="1" value="2500">1<BR> <input type="radio" name="2" value="1500">2<br><br> <input type="radio" name="3" value="1000">3<BR> <input type="radio" name="4" value="500">4<br><br> <input type="radio" name="5" value="250">5<br><br> </td> </tr> <tr><td colspan="2"><input type="submit" value="OK" class="button"><input type="reset" value="Reset"></td></tr> </table></form> Link to comment https://forums.phpfreaks.com/topic/112302-form-set-amount/ Share on other sites More sharing options...
phpzone Posted June 28, 2008 Share Posted June 28, 2008 You must give your radio buttons the same name and then simply check $_POST['choice'] to get its value. In this case I would do: <input type="radio" name="choice" value="2500">1<BR> <input type="radio" name="choice" value="1500">2<br><br> <input type="radio" name="choice" value="1000">3<BR> <input type="radio" name="choice" value="500">4<br><br> <input type="radio" name="choice" value="250">5<br><br> You can then get the value: $choice = $_POST['choice']; which would give you 250, or 500, etc. etc. You can do the same with checkboxes, however you will then allow multiple choices, so you would suffix your HTML input name with [] such as <input type="checkbox" name="choices[]" value="2500">1<BR> <input type="checkbox" name="choices[]" value="1500">2<br><br> <input type="checkbox" name="choices[]" value="1000">3<BR> <input type="checkbox" name="choices[]" value="500">4<br><br> <input type="checkbox" name="choices[]" value="250">5<br><br> You would have to process this postback like so: $multi_choices = $_POST['choices']; foreach( $multi_choices as $choice ) { print <<<_MESSAGE <p>Use has chosen $choice</p> _MESSAGE } Hope this helps. Link to comment https://forums.phpfreaks.com/topic/112302-form-set-amount/#findComment-576604 Share on other sites More sharing options...
kiki Posted June 29, 2008 Author Share Posted June 29, 2008 do i need to put this part down?: foreach( $multi_choices as $choice ) { print <<<_MESSAGE <p>Use has chosen $choice</p> _MESSAGE } Link to comment https://forums.phpfreaks.com/topic/112302-form-set-amount/#findComment-577015 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.