当表单为空时,我希望我的错误信息显示在警告框中。我不熟悉PHP。我张贴了关于这昨晚取得联系形式的工作,感谢大家在这里我得到了它的工作,但遇到了一个最后的问题。
<?php
$errors = '';
$myemail = 'example@gmail.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']))
{
$errors .= echo 'alert("Error: all fields are required")';
}
不确定是否可以使用。= echo 'alert'
您需要将其更改为以下内容:-
<?php
$errors = '';
$myemail = '3dart.nick@gmail.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']))
{
echo '<script>alert("Error: all fields are required");</script>';
}
echo用于输出字符串。它返回void类型
void echo ( string $arg1 [, string $... ] );
所以,在你的代码中删除$error =
请使用:echo 'alert("Error: all fields are required")';
但是,要在客户端浏览器上运行警报功能,尝试这样做;进入<script></script>
:
echo "<script>alert('Error: all fields are required')</script>";
这是php的url手册:http://php.net/manual/en/function.echo.php