gpt4 book ai didi

php - 需要 php 表单来命名哪些必填字段尚未填写

转载 作者:行者123 更新时间:2023-12-02 07:53:21 29 4
gpt4 key购买 nike

我的 php 表单有必填字段,但消息没有让用户知道哪个字段没有输入。我该怎么做?

//if statement to check required fields
if ($name && $phone && $email && && $address && $city && $state && $zip && $month && $date && $year && $contact)...
//if some required fields were not filled out
echo "Please make sure you fill in all required fields<br>Click <a href=\"javascript:history.back(1)\">here</a> to return to our form.";
}

最佳答案

这是一个简单的例子......

// An array of required fields, these fields must not be empty
$requiredFields = array('name', 'email');

// Iterate through required fields
foreach ($requiredFields as $fieldName)
{
// Does this field have a value?
if (empty($_REQUEST[$fieldName]))
{
echo 'rawr! go back and fill out ' . $fieldName . "<br>\n";
}
}

关于php - 需要 php 表单来命名哪些必填字段尚未填写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2366947/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com