0

我在验证字段是否为空或已满时遇到问题。下面的代码会有所帮助。

以下不是我表格的全部内容,只是您需要了解的部分。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>

我使用此脚本对上面的选择选项进行无选择。Javascript

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

这不是它的全部 PHP,只是我遇到问题的部分。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 ) 

这是我遇到麻烦的部分:

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

我需要该部分来查看是否选择了“下拉菜单”之一,如果没有给出错误。

4

1 回答 1

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

或者

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

或者

!in_array($subject, array("Other", "Service inquiries", "Request for quote"), true);
于 2013-05-10T02:32:39.010 回答