PHP contact form with radio buttons |
PHP contact form with radio buttons |
Louffeman |
Jun 21 2014, 04:39 AM
Post
#1
|
Member Group: Members Posts: 69 Joined: 21-June 14 Member No.: 21,123 |
hi,
i have a contact form script, i can send and receive, but without radio buttons, le wamp server indicated l'error: Undefined index: action in C:\wampserver32\www\test\index.php on line 2. i wish someone cans help me to modify my script that i could receive the radio buttons: 1.<?php 2. $action=$_REQUEST['action']; 3.if ($action=="") /* display the contact form */ 4. { 5. ?> 6. <form action="" method="POST" enctype="multipart/form-data"> 7. <input type="hidden" name="action" value="submit"> 8. <input type="radio" name="veg" value="cabbage" <?php if(!isset($veg)){print " 9. checked=\"checked\"";} if(isset($veg) && $veg == "cabbage"){print " 10.checked=\"checked\"";} ?>> Mrs 11. <input type="radio" name="veg" value="onion" <?php if(isset($veg) && $veg == "onion"){print " checked=\"checked\"";} ?>> Mr <br> 12 your name:<br> 13. <input name="name" type="text" value="" size="40"/><br> 14. your email:<br> 15. <input name="email" type="text" value="" size="40"/><br> 16. Votre adresse:<br> 17. <input name="message" type="text" value="" size="80"/><br> 18. <input type="submit" value="send"/> 19. </form> 20. <?php 21. } 22. else /* send the submitted data */ 23. { 24. $name=$_REQUEST['name']; 25. $email=$_REQUEST['email']; 26. $message=$_REQUEST['message']; 27. if (($name=="")||($email=="")||($message=="")) 28. { 29. echo "fill all the cases, <a href=\"\">the form</a> please!."; 31. } 32. else{ 33. $from="From: $name<$email>\r\nReturn-path: $email"; 34. $subject="Message sent using your contact form"; 35. mail("1234@club-internet.fr", $subject, $message, $from); 36. echo "Email has been sent!"; 37. } 38. } 39. ?> |
Christian J |
Jun 21 2014, 06:45 AM
Post
#2
|
. Group: WDG Moderators Posts: 9,652 Joined: 10-August 06 Member No.: 7 |
hi, i have a contact form script, i can send and receive, but without radio buttons You must retrieve the gender buttons' data as well, for example like this: CODE $message="Gender: ". $_REQUEST['veg'] . "\n\nAddress: " . $_REQUEST['message']; I also suggest you use more meaningful variable names than "veg" for gender, or "message" for Address. QUOTE le wamp server indicated l'error: Undefined index: action in C:\wampserver32\www\test\index.php on line 2. That's just because $_REQUEST['action'] is not available when the page is first loaded. Use PHP's isset() function to check this. As a side note, there are some logical errors here: CODE if(!isset($veg)) { print "checked=\"checked\""; } if(isset($veg) && $veg == "cabbage") { print "checked=\"checked\""; } --since ($action=="") and isset($veg) are never true at the same time, the above check becomes meaningless. Just hardcode the CHECKED attribute for one of the buttons, instead of using PHP. |
Lo-Fi Version | Time is now: 18th April 2024 - 12:23 PM |