我有一個聯繫表,我需要在PHP中驗證以檢查每個字段是否被正確填充。在PHP中驗證聯繫表格
以下是我有:
//Post fields
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_services = $_POST['services'];
$field_it = $_POST['it'];
$field_location = $_POST['location'];
$field_message = $_POST['message'];
//mail_to omitted
//Validation of contact form
$errormessage = '';
if($field_name == ''){
$errormessage += 'You have not entered your Name\n';
}
if($field_email == ''){
$errormessage += 'You have not entered your Email Address\n';
}
if($field_services == ''){
$errormessage += 'You have not chosen the service you require\n';
}
if($field_it == ''){
$errormessage += 'You have not chosen the Date of your event\n';
}
if($field_location == ''){
$errormessage += 'You have not entered the location of your event\n';
}
if($errormessage != ''){ ?>
<script language="javascript" type="text/javascript">
alert('The following fields have not neen entered correctly\n<?php echo "$errormessage" ?>');
window.location = 'contact.html';
</script>
<?php }
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to [email protected]');
window.location = 'contact.html';
</script>
<?php
}
?>
這什麼也不做,當我試圖提交一個空的接觸形式,它應該提醒特定領域,其沒有填補的用戶,但事實並非如此。它只是把我帶到一個空白的白頁。
任何人都可以幫我找到我要去的地方嗎?
開始發送郵件之前進行任何驗證 – 2013-08-29 22:34:51
空白頁?你的錯誤日誌說什麼? – James