Php 如何使optin表单字段符合我的登录页自定义邮件程序的要求
我正在使用以下代码作为我的登录页上的optin form邮件Php 如何使optin表单字段符合我的登录页自定义邮件程序的要求,php,email,Php,Email,我正在使用以下代码作为我的登录页上的optin form邮件 <?php /* Set e-mail recipient */ $myemail = "MYEMAIL@EMAIL.COM"; /* Check all form inputs using check_input function */ $fname = check_input($_POST['fname'], "Enter your first name"); $lname = check_input($_
<?php
/* Set e-mail recipient */
$myemail = "MYEMAIL@EMAIL.COM";
/* Check all form inputs using check_input function */
$fname = check_input($_POST['fname'], "Enter your first name");
$lname = check_input($_POST['lname'], "Enter your last name");
$email = check_input($_POST['email']);
$phone = check_input($_POST['phone']);
$resort = check_input($_POST['resort']);
$amount = check_input($_POST['amount']);
$call = check_input($_POST['call']);
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
$website = '';
}
/* Let's prepare the message for the e-mail */
$message = "Hello!
Your contact form has been submitted by:
First Name : $fname
Last Name : $lname
E-mail: $email
Phone : $phone
Resort: $resort
Amount: $amount
Call : $call
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: index.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
if (strtolower($_POST['code']) != 'mycode') {die('Wrong access code');}
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
现在,当人们提交表单时,我希望所有字段都是必需的,并且在他/她遗漏字段的情况下显示一条错误消息。只需检查$\u POST值是否为空,如果为空,则返回一个错误。您也可以使用javascript实现类似的功能。您可以在PHP端的$\u POST变量上执行isset,或者在html端的输入元素中添加required。正如Andrei所指出的,最好使用java脚本进行验证,除非您有充分的理由在PHP中进行验证。谷歌搜索在顶部显示了这两个结果。我不想使用java,因为我个人作为一个用户,不喜欢一个网站弹出一些dailoug框,我希望有一个简单的错误消息,就像我们在注册表单中看到的,当我们错过一个必填字段时。此字段为必填字段