0

我有一个 php 联系表,我正在尝试编辑以满足我的需要。目前,需要填写每个字段才能使表单正常工作。为了使某些字段可选,我需要编辑什么?下面不是完整的脚本,但我感觉它是我需要做的最重要的领域部分。

谢谢

$name    = $_POST['name'];
$email  = $_POST['email'];
$phone  = $_POST['phone'];
$date    = $_POST['date'];
$guests  = $_POST['guests'];
$subject  = $_POST['subject'];
$comments = $_POST['comments'];

if (isset($_POST['verify'])) : 
    $posted_verify   = $_POST['verify']; 
    $posted_verify   = md5($posted_verify); 
else :
    $posted_verify = '';
endif;

// Important Variables
$session_verify = $_SESSION['verify'];

if (empty($session_verify)) $session_verify = $_COOKIE['verify'];

$error = '';

    if(trim($name) == '') {
        $error .= '<li>Your name is required.</li>';
    }

    if(trim($date) == '') {
        $error .= '<li>Your event date is required.</li>';
    }

    if(trim($email) == '') {
        $error .= '<li>Your e-mail address is required.</li>';
    } elseif(!isEmail($email)) {
        $error .= '<li>You have entered an invalid e-mail address.</li>';
    }

    if(trim($phone) == '') {
        $error .= '<li>Your phone number is required.</li>';
    } elseif(!is_numeric($phone)) {
        $error .= '<li>Your phone number can only contain digits.</li>';
    }


    if(trim($comments) == '') {
        $error .= '<li>You must enter a message to send.</li>';
    }

    if(trim($guests) == '') {
        $error .= '<li>The number of guests is required.</li>';
    } elseif(!is_numeric($guests)) {
        $error .= '<li>Your phone number can only contain digits.</li>';
    }
4

1 回答 1

1

删除您希望成为可选变量的 if 语句。

示例删除此名称为可选: if(trim($name) == '') { $error .= '<li>Your name is required.</li>'; }

于 2012-08-02T02:52:32.760 回答