jon4433 Posted February 19, 2012 Share Posted February 19, 2012 So I have 2 radio buttons, one called 'Yes' and the other called 'No'. I want the user to choose one of them since they are required, but how would I send which choice they have choosen? I have the mail form out set out of working, but i'm not too sure on how I would send the option that the user chooses. <?php if($_POST['submit']) { $username = $_POST['username']; $email = $_POST['email']; $age = $_POST['age']; $location = $_POST['location']; $duration = $_POST['duration']; $no = $_POST['no']; $yes = $_POST['yes']; //$griefed = $_POST['griefed']; $access = $_POST['access']; $builder = $_POST['builder']; $fill = $_POST['fill']; if(empty($username)){ echo "The username field was blank. Please go back and fill in the required fields.<br>"; } if(empty($email)){ echo "The email field was blank. Please go back and fill in the required fields.<br>"; } if(empty($age)){ echo "The age field was blank. Please go back and fill in the required fields.<br>"; } if(empty($location)){ echo "The location field was blank. Please go back and fill in the required fields.<br>"; } if(empty($duration)){ echo "The duration field was blank. Please go back and fill in the required fields.<br>"; } if(empty($access)){ echo "The access field was blank. Please go back and fill in the required fields.<br>"; } if(empty($builder)){ echo "The builder field was blank. Please go back and fill in the required fields.<br>"; } if(empty($fill)){ echo "The more details field was blank. Please go back and fill in the required fields.<br>"; } else{ if($username && $email && $age && $location && $duration && $access && $builder && $fill){ $to = "[email protected]"; $subject = "Creative World Application"; $message = "Username: $username Email: $email Age: $age Location: $location Duration on the server: $duration Access to the new world: $access Are you a good builder: $builder Anything else that we should know: $fill"; $headers = "From: $email /n"; mail($to,$subject,$message,$headers); echo "Application was sent!"; } else { echo "All fields are required!"; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> body { font-family: Minecraft; background-image: url(images/background.png); background-size:100% 100%; background-attachment: fixed; background-repeat: repeat-x; background-position: left top; background-color: #999999; } body,td,th { color: #FFF; } </style> </head> <body> <div id="wrap"> <!--Banner--> <div id="header_2"><a href="index.html"><img src="images/banner.png"/></a></div> <div id="error"></div> <!--White-List form--> <div id="whitelist" align ="right"> <form method="POST"> In-Game Name: <input type="text" name="username"/><p> Email: <input type="text" name="email" /><p> Age: <input type="text" name="age" /><p> Location: <input type="text" name="location" /><p> How long have you beed on Dawncraft: <input type="text" name="duration" /><p> Have you ever griefed: <label> <input type="radio" name="no" value="no" id="choice_0" /> No</label> <br /> <label> <input type="radio" name="yes" value="yes" id="choice_1" /> Yes</label><br /> Why do you want access to the creative world:<textarea name="access"></textarea><p> Do you consider yourself to be a good builder: <textarea name="builder"></textarea><p> Anything else that we should know: <textarea name="fill"></textarea><p> <input type="submit" name="submit" value="Submit" /><br /> </form> </div> <!--Footer--> <center><div id="footer_2">Dawncraft© 2011 - 2012</div></center> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/257311-sending-different-radio-button-choices-in-the-mail-function/ Share on other sites More sharing options...
sunfighter Posted February 19, 2012 Share Posted February 19, 2012 First your boxes must share the same name: Have you ever griefed: <label> <input type="radio" name="cbox" value="no" id="choice_0" /> No</label> <br /> <label> <input type="radio" name="cbox" value="yes" id="choice_1" /> Yes</label><br /> Your php to find the value is: $cbox = $_POST['cbox']; The var. cbox will be 'yes' or 'no' depending on which is selected. Link to comment https://forums.phpfreaks.com/topic/257311-sending-different-radio-button-choices-in-the-mail-function/#findComment-1318963 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.