我正在使用我从另一个创建的网站上更改过的表单,该表单可以正常工作,并且由于某种原因它不在此处工作。我已经完成了一百次代码,并且错过了重要的线索!请帮忙!我的表单遗漏了什么?
该表格包含php验证。如果未填写必填字段,则会再次显示表单,其中填写的内容会自动放入新表单中。除了它不会自动填充这些完整的字段,并且它不验证有效的提交。
我猜数据未被正确发布,但我看不到问题出在哪里!
这里的最初形式:
<form name="userform" method="post" action="send_form_email.php">
<table>
<tr>
<td class="form_item_name">Name:</td><td><input type="text" name="name"></td>
</tr>
<tr>
<td class="form_item_name">Company name:</td><td><input type="text" name="company"> </td>
</tr>
<tr>
<td class="form_item_name">Email:</td><td><input type="text" name="email"></td>
</tr>
<tr>
<td class="form_item_name">Phone:</td><td><input type="text" name="phone"></td>
</tr>
<tr>
<td class="form_item_name"></td>
<td>
<select name="subject">
<option value="Requesting A Quote" selected="selected">Requesting A Quote</option>
<option value="Product/Service Support">Product/Service Support</option>
<option value="General Enquiry">General Enquiry</option>
</select>
</td>
</tr>
<tr>
<td class="form_item_name">Your comments:</td><td><textarea style="resize:none; width:350px;" name="comments" rows="10" wrap="hard"></textarea><br />
<br />
<input class="button_send" type="image" value=" " src="images/transparent.gif"></form>
而这里的行动PHP(send_form_email.php):
<?php
if(strlen($name) > 2 &&
strlen($email) > 2 &&
strlen($comments) > 2) {
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_to = "[email protected]";
$email_from = "Website: Contact Us";
if (strpos($subject,'General Enquiry') !== false) {
$email_subject = "General Enquiry";
}
elseif (strpos($subject,'Product/Service Support') !== false) {
$email_subject = "Product/Service Support";
}
elseif (strpos($subject,'Request A Quote') !== false) {
$email_subject = "Quote Request";
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Company: ".clean_string($company)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Phone: ".clean_string($phone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
"Reply-To: ".$email."\r\n" .
"X-Mailer: PHP/" . phpversion();
@mail($email_to, $email_subject, $email_message);
?>
<font face="times new roman" color="#FFF" size="+3">Thanks for that, your message has been sent!</font><br>
<a href="http://www.happytobevisuals.co.nz" class="nav_ingredients">Click here to go back to the home page</a>
<?php
}else{
?>
<font face="times new roman" color="#FFF" size="+3">Woops! Missed something ...</font>
<br>
<br>
<form name="userform" method="post" onsubmit="return validate();" action="send_form_email.php">
<table>
<tr>
<td class="form_item_name">Name:</td><td><input type="text" name="name" value="<?php echo $name;?>"></td>
</tr>
<tr>
<td class="form_item_name">Company name:</td><td><input type="text" name="company" value="<?php echo $company;?>"></td>
</tr>
<tr>
<td class="form_item_name">Email:</td><td><input type="text" name="email" value="<?php echo $email;?>"></td>
</tr>
<tr>
<td class="form_item_name">Phone:</td><td><input type="text" name="phone" value="<?php echo $phone;?>"></td>
</tr>
<tr>
<td class="form_item_name"></td>
<td>
//this next bit's about autofilling the dropdown to reflect their previous selection
<?php
if (strpos($subject,'General Enquiry') !== false) {
echo '<select name="subject">
<option value="General Enquiry">General Enquiry</option>
<option value="Product/Service Support">Product/Service Support</option>
<option value="Complaint">Complaint</option>
</select>';
}
if (strpos($subject,'Product/Service Support') !== false) {
echo '<select name="subject">
<option value="General Enquiry">General Enquiry</option>
<option value="Product/Service Support" selected="selected">Product/Service Support</option>
<option value="Complaint">Complaint</option>
</select>';
}
if (strpos($subject,'Complaint') !== false) {
echo '<select name="subject">
<option value="General Enquiry">General Enquiry</option>
<option value="Product/Service Support">Product/Service Support</option>
<option value="Complaint" selected="selected">Complaint</option>
</select>';
}
}
?>
</td>
</tr>
<tr>
<td class="form_item_name">Your comments:</td><td><textarea style="resize:none; width:350px;" name="comments" rows="10" wrap="hard"><?php echo $comments ?></textarea><br />
<br />
<input type="submit" value="valid"></form>
所以......你能看到吗?所有帮助赞赏!
PS。是否有更快的方法在stackoverflow中将代码放入块中,而不是在每行之前手动添加四个空格?欢呼:)
您可以选择您的代码并单击格式代码的“{}”图标。 –
是的,只需点击一个按钮,就可以更快地将所有代码放入一个块中。只需选择所有代码并点击编辑器上的{}按钮。这将把选定的文本块合并为代码格式,您不必手动完成。 – Devner
当你在它的时候,确保你正确地编码变量,像这样'value =“<?php echo htmlspecialchars($ company)?>”' –