我正在嘗試使用HTML,PHP和bootstrap twitter在網站上創建表單(http://youngliferaffle.com/)。我一直在瀏覽如何創建它的幾個教程,但我認爲我在位置方面遇到了問題 - 例如在用戶發生錯誤或提交答案之後重定位用戶。我也是PHP新手。我真的很感激幫助!謝謝!使用HTML和PHP創建表格
主要問題:
- 「太多重定向到該網頁」 /可能是由於
- 用戶不被重定向到正確的頁面提交或到期後餅乾
- 由於沒有收到提交的電子郵件壞提交
這裏是我的HTML表單的一部分:
<form method="POST" action="contact-form-submission.php">
<fieldset>
<label><strong>Sign-Up</strong></label>
<input type="text" class="name" name="cname" id="name" placeholder="Full Name"></input>
<input type="text" class="phone" name="phone" id="phone" placeholder="Phone Number"></input>
<input type="text" class="email" name="email" id="email" placeholder="Email Address"></input>
<div class="form-actions">
<input type="submit" name="save" value="Send">
</div>
</fieldset>
</form>
這是我的PHP形式
// check for form submission - if it doesn't exist then send back to contact form
if (!isset($_POST['save']) || $_POST['save'] != 'contact') {
header('Location: contact-form-submission.php');
exit;
}
// get the posted data
$name = $_POST['contact_name'];
$email_address = $_POST['contact_email'];
$phone = $_POST['contact_phone'];
// check that a name was entered
if (empty($name))
$error = 'You must enter your name.';
// check that an email address was entered
elseif (empty($email_address))
$error = 'You must enter your email address.';
// check for a valid email address
elseif (!preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', $email_address))
$error = 'You must enter a valid email address.';
// check that a phone number was entered
elseif (empty($phone))
$error = 'You must enter a phone number.';
// check if an error was found - if there was, send the user back to the form
if (isset($error)) {
//Am I putting the wrong location?
header('Location: contact-form-submission.php?e='.urlencode($error)); exit;
}
// write the email content
$email_content = "Name: $name\n";
$email_content .= "Email Address: $email_address\n";
$email_content .= "Phone:\n\n$phone";
// send the email
mail ("myemail.com", "New Contact Message", $email_content);
// send the user back to the form
//And This is where I'm having trouble with! the Location part
header('Location: contact-form-submission.phps='.urlencode('Thank you for your message.'));
exit;
那麼你有什麼具體問題? – 2013-05-08 19:38:49
該腳本何時執行?是否在GET contact-form-submission.php,POST contact-form-submission.php或其他一些URL之後? – Mateusz 2013-05-08 19:39:30
如果您嘗試提交表單,即使沒有正確輸入,它也會重定向您,並說有太多重定向到網頁(http://youngliferaffle.com/contact-form-submission.php)。 此外,即使我確實填寫了它,它也會表示相同,但我沒有收到電子郵件。 – user2363671 2013-05-08 19:40:31