我希望检查值first_name,last_name和email。如果值为空,则重新加载页面。我有重新加载页面时显示的错误消息,如果这些值是http://cdubach.com ....,我相信我的逻辑是正确的但由于某种原因它不起作用。我很感激你的帮助!
<form name="contactform" method="post" action="
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["first_name"]) || empty($_POST["last_name"]) || empty($_POST["email"])) {
echo "";
} elseif (isset($_POST["first_name"]) && isset($_POST["last_name"]) && isset($_POST["email"])) {
echo "http://cdubach.com/inc/send_form_email.php";
}
}
?>">
答案 0 :(得分:0)
如果您直接在表单的action
标记中插入PHP代码,那么它将无效:
<form name="contactform" method="post">
<input type="submit" value="click" name="submit">
</form>
<?php
if (isset($_POST['submit'])) {
display();
}
function display() {
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if (empty($_POST["first_name"]) || empty($_POST["last_name"]) || empty($_POST["email"])) {
echo "";
} else if (isset($_POST["first_name"]) && isset($_POST["last_name"]) && isset($_POST["email"])) {
echo "http://cdubach.com/inc/send_form_email.php";
}
else {
}
}
}
?>
希望这有帮助,谢谢!