Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/155352-solved-required-fields-in-form/
Share on other sites

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.