0

I am having an issue validating that a field is empty or full. The code below will help.

The below is not the whole piece of my form, just the part you need to know. HTML:

<form action="" method="post" id="all_message">
    <ul>
        <li>
            <label for="subject">Subject</label><br />
            <select id="No_dropdown" name="Dropown_select">
                <option value="Request for quote">Request for quote</option>
                <option value="Service inquiries">Service inquiries</option>
                <option value="Other">Other</option>
            </select>
        </li>
        <li>
            <input type="submit" value="Send" name="submit" />
        </li>
    </ul>
</form>

I use this script to make a no selection on the select option above. Javascript

<script language="javascript" type="text/javascript">
document.getElementById("No_dropdown").selectedIndex = -1;
</script>

This is not the whole PHP for it, just the part I'm having trouble with. PHP:

$subject =      $_POST['Dropown_select'];

if (empty($name) === true || empty($email) === true || empty($phone) === true || 
    !($subject === "Other" || "Service inquiries" || "Request for quote") ||   
    empty($message) === true ) 

This is the part I am having troubles with:

!($subject === "Other" || "Service inquiries" || "Request for quote")

I need that part to see if one of the 'dropdowns' is selected and if not give an error.

1 Answer 1

5
!($subject === "Other" || $subject === "Service inquiries" || $subject === "Request for quote")

or

($subject !== "Other" && $subject !== "Service inquiries" && $subject !== "Request for quote")

or

!in_array($subject, array("Other", "Service inquiries", "Request for quote"), true);
Sign up to request clarification or add additional context in comments.

1 Comment

I used the second method and it works as expected. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.