Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Radio Buttons php handling

Featured Replies

Hi,

 

I'm working on what should be a simple form. I guess I just don't know how to handle radio button selections which I need to send to an email address.

 

When I select an option and hit submit, the browser finds the php file (contact.php) but nothing happens. So I guess the problem is with the php file - everything seems to be working in the html (I think).

 

This is where I'm at so far: http://www.clearstreamdesign.co.uk/form/formtest.html

 

Here's the html and below that the php I'm using. Any advice really appreciated.

 

<!DOCTYPE html>
<html>
 <head>
         <meta charset="utf-8">
       <title>Name The Cow</title>

<link href="css/formstyle.css" rel="stylesheet"> 

<script type="text/javascript" src="js/blinking_text.js"></script>

</head>
 <body>
<div id="formbox">


<form method="post" action="contact.php"> 
<div class="tag">Please Choose A Name</div>
		<div class="button-holder">
	<input type="radio" id="radio-2-1" name="cowname" value="buttercup" class="regular-radio big-radio" /><label for="radio-2-1"></label><br /><br />
			<input type="radio" id="radio-2-2" name="cowname" value="clarabell" class="regular-radio big-radio" /><label for="radio-2-2"></label><br /><br />
		<input type="radio" id="radio-2-3" name="cowname" value="delilah" class="regular-radio big-radio" checked /><label for="radio-2-3"></label><br /><br />
			<input type="radio" id="radio-2-4" name="cowname" value="emily" class="regular-radio big-radio" /><label for="radio-2-4"></label><br /><br />
				 <input type="radio" id="radio-2-5" name="cowname" value="esme" class="regular-radio big-radio" /><label for="radio-2-5"></label><br /><br />
			<input type="radio" id="radio-2-6" name="cowname" value="eva" class="regular-radio big-radio" /><label for="radio-2-6"></label><br /><br />
</div>
<div class="label-holder">
<span class="formlabel">BUTTERCUP</span>
<p><span class="formlabel">CLARABELL</span>
<p><span class="formlabel">DELILAH</span></p>
<p><span class="formlabel">EMILY</span></p>
<p><span class="formlabel">ESME</span></p>
<p><span class="formlabel">EVA</span></p>
</div>
<p><div class="form-group">
            <button type="submit" class="myButton">Submit</a></button> 
            <button type="reset" class="myButton">Reset</a></button></p> </div></p>
 </form>


</form> 

	</div>	

</div>    </div></div>
<div id="terms">


 </body>

</html>

And the PHP

 

 <?php
$EmailFrom = "Form entry";
$EmailTo = "me@gmail.com";
$Subject = "Name Cow Entry";
$Cowname = Trim(stripslashes($_POST['cowname'])); 



// prepare email body text
$Body = "";
$Body .= "EmailFrom: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Subject: ";
$Body .= $Subject;
$Body .= "\n";
$Body .= "Cowname: ";
$Body .= $Cowname;
$Body .= "\n";



// send email 
$success = mail($EmailTo, $Subject, $ Body, $Cowname, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=messagesent.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=messagenotsent.html\">";
  
  function check_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
}
?>

 

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.