mcho74 Posted October 30, 2009 Share Posted October 30, 2009 Hi there, I'm a newbie to PHP and I've been stumbling my way through some PHP contact form script tutorials and could use some more guidance. Can you tell me what I'm doing wrong? 1 - I don't know how to add the code correctly for my radio buttons into my PHP script. 2 - Even without trying to add the botched radio button code, I can't get my script to direct me to the proper html header after I input the info into the contact form and click submit. It just goes back to the same Contact.html instead of the ThankYou.html. I have separate html and PHP files. Here is my html code and then the PHP code. <form id="Contactform" name="Contactform" method="post" action="sendmail.php"> <table width="285" height="220" border="0" cellspacing="0"> <tr> <td width="88">Name:</td> <td width="240"><input name="Name" type="text" id="Name" size="25" maxlength="100" /></td> </tr> <tr> <td>Address:</td> <td><input name="Address" type="text" id="Address" size="25" maxlength="100" /></td> </tr> <tr> <td>City:</td> <td><input name="City" type="text" id="City" size="25" maxlength="100" /></td> </tr> <tr> <td>State/Prov:</td> <td><input name="State/Prov" type="text" id="State/Prov" size="25" maxlength="100" /></td> </tr> <tr> <td>Zip</td> <td><input name="Zip" type="text" id="Zip" size="25" maxlength="100" /></td> </tr> <tr> <td>Country:</td> <td><input name="Country" type="text" id="Country" size="25" maxlength="100" /></td> </tr> <tr> <td>Phone:</td> <td><input name="Phone" type="text" id="Phone" size="25" maxlength="100" /></td> </tr> <tr> <td>Email:</td> <td><input name="Email" type="text" id="Email" size="25" maxlength="100" /></td> </tr> </table> <p>Are you interested in financing opportunities with Twin Seas? <label> <input type="radio" name="Financing" id="Financing Yes" value="Financing Yes" /> </label> Yes <label> <input type="radio" name="Financing" id="Financing No" value="Financing No" /> </label> No</p> <p>Comments or Questions:<br /> <label> <textarea name="Comments" id="Comments" cols="45" rows="4"></textarea> </label> </p> <p> <label> <input type="submit" name="Submit" id="Submit" value="Submit" /> </label> <label> <input type="reset" name="Reset" id="Reset" value="Reset" /> </label> </p> </form> <?php $Name = $_REQUEST['Name'] ; $Address = $_REQUEST['Address'] ; $City = $_REQUEST['City'] ; $StateProv = $_REQUEST['State/Prov'] ; $Zip = $_REQUEST['Zip'] ; $Country = $_REQUEST['Country'] ; $Phone = $_REQUEST['Phone'] ; $Email = $_REQUEST['Email'] ; $Comments = $_REQUEST['Comments'] ; $Financing Yes_status = 'unchecked'; $Financing No_status = 'unchecked'; if (isset($_POST['Submit'])) { $selected_radio = $_POST['Financing']; if ($selected_radio = = 'Financing Yes') { $Financing Yes_status = 'checked'; } else if ($selected_radio = = 'Financing No') { $Financing No_status = 'checked'; } } if ( preg_match( "/[\r\n]/", $Name ) || preg_match( "/[\r\n]/", $Email ) ) { header( "Location: http://www.twinseasdevelopmentcabosanlucas.com/Error.html" ); exit ; } if (!isset($_REQUEST['email'])) { header( "Location: http://www.twinseasdevelopmentcabosanlucas.com/Contact.html" ); } elseif (empty($Name) || empty($Phone) || empty($Email)) { header( "Location: http://www.twinseasdevelopmentcabosanlucas.com/Error.html" ); } else { mail( "mcho74@verizon.net", "Contact Form Results", "From: $Name <$Email>" ); header( "Location: http://www.twinseasdevelopmentcabosanlucas.com/ThankYou.html" ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/179657-contact-form-w-radio-buttons-questions/ Share on other sites More sharing options...
KevinM1 Posted October 30, 2009 Share Posted October 30, 2009 You're processing the radio buttons correctly. However, the overall design of your form handler needs to be addressed. There are two steps you need to take, in order: 1. Check to see if the form has been submitted 2. Check each form input manually So, the form handler should have the structure of: if(isset($_POST['submit'])) { if(isset($_POST['name']) && isset($_POST['email'])) { //run regex checks } else { //non-existent data error } //... } Essentially, you need to check for the existence of an input value before you can use it. Also, you shouldn't use the $_REQUEST array. Use the one you specify in your form's method, in this case $_POST. Right now, your e-mail script is open to processing data sent via query string (i.e., in the url), which you probably don't want. Quote Link to comment https://forums.phpfreaks.com/topic/179657-contact-form-w-radio-buttons-questions/#findComment-947999 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.