dongxiaoxiao1983
2012-07-02 02:35停止空表单提交PHP
I have been trying to implement server validation to prevent blank emails in my contact us page, but I am not sure on how to do it in PHP, here is my code:
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_tel = $_POST['cf_tel'];
$field_message = $_POST['cf_message'];
$mail_to = 'test@test.com, test@test.com, test@test.com';
$subject = 'Just iStuff Mobile Contact Us: '.$field_name;
$body_message = 'From: '.$field_name."
";
$body_message .= 'E-mail: '.$field_email."
";
$body_message .= 'Telephone Number: '.$field_tel."
";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."
";
$headers .= 'Reply-To: '.$field_email."
";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for your email, we have received your message and will reply within the next few days.');
window.location = 'contactus.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed, please try again or email test@test.com');
window.location = 'contactus.html';
</script>
<?php
}
?>
Can anyone help me to do this, the tutorials online do not cover this way of doing it...
Thanks
- 点赞
- 回答
- 收藏
- 复制链接分享
4条回答
为你推荐
- 如果在ajax回调中验证失败,我如何停止提交表单
- javascript
- ajax
- forms
- jquery
- php
- 3个回答
- 当我使用php提交表单时,如何从清空中停止勾选框输入?
- php
- 2个回答
- 无法停止打开Action目标的AJAX表单提交
- javascript
- ajax
- forms
- jquery
- php
- 1个回答
- 如何处理多个表单?,在提交时停止重新加载页面?
- ajax
- forms
- php
- jquery
- html
- 2个回答
- javascript确认不会停止提交表单
- javascript
- php
- 4个回答
换一换