Y2Jackie Posted April 23, 2009 Share Posted April 23, 2009 Hi, I'm a noob at PHP (this is my first script) but need to use it so I can add in the reCaptcha code. It all works except for one thing... In my form file I have: <select name="contactMethod" id="contactMethod"> <option selected="selected">Please Choose</option> <option>Home Phone</option> <option>Mobile Phone</option> <option>Email</option> </select> In my sendmail.php file I have the following statement: if (!isset($_REQUEST['emailAddress'])) { header("Location: myformlink.php"); } elseif (empty($EmailAddress) || empty($Enquiry) || empty($FirstName) || empty($Surname) || empty($ContactMethod)){ header("Expires: Mon, 20 Dec 1998 01:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); where $ContactMethod = $_REQUEST['contactMethod']; Because "Please Choose" is automatically selected, it validates as if the user has selected it. I need Please Choose at the top, but I also need the script to be able to understand that if that is selected, then it is to consider it as if it has no information and fail the test. Is this possible? Thank you! Jackie Quote Link to comment https://forums.phpfreaks.com/topic/155352-solved-required-fields-in-form/ Share on other sites More sharing options...
MatthewJ Posted April 23, 2009 Share Posted April 23, 2009 if (!isset($_REQUEST['emailAddress'])) { header("Location: myformlink.php"); } elseif (empty($EmailAddress) || empty($Enquiry) || empty($FirstName) || empty($Surname) || $ContactMethod == "Choose") { ..... Give that a try, it will check the ContactMethod var for the word choose since it will not be empty. Quote Link to comment https://forums.phpfreaks.com/topic/155352-solved-required-fields-in-form/#findComment-817321 Share on other sites More sharing options...
Y2Jackie Posted April 23, 2009 Author Share Posted April 23, 2009 I've tried it but it doesn't seem to be working I've tried "Choose" and "Please Choose" Quote Link to comment https://forums.phpfreaks.com/topic/155352-solved-required-fields-in-form/#findComment-817329 Share on other sites More sharing options...
mikesta707 Posted April 23, 2009 Share Posted April 23, 2009 the reason that it wont work is because you have to set a value to the option. instead of <option selected="selected">Please Choose</option> try <option selected="selected" value="choose">Please Choose</option> Then try and see if what matthewJ posted will work Quote Link to comment https://forums.phpfreaks.com/topic/155352-solved-required-fields-in-form/#findComment-817562 Share on other sites More sharing options...
Y2Jackie Posted April 24, 2009 Author Share Posted April 24, 2009 Thanks Matthew and Mike, I've got it working now Quote Link to comment https://forums.phpfreaks.com/topic/155352-solved-required-fields-in-form/#findComment-817973 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.