0

我正在使用从我创建的另一个站点更改的表单,该表单有效,但由于某种原因它在这里不起作用。我已经通过代码一百次了,我错过了重要的线索!

该表单包括 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 = "sales@happytobevisuals.com";
$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上是否有比在每行之前手动添加四个空格更快的方法将代码放入块中?干杯:)

4

3 回答 3

0

您可能在此主机上关闭了 register_globals (从安全角度来看这是一件非常好的事情 - 请参阅http://php.net/manual/en/security.globals.php!),这解释了为什么这对您的其他主机但不在这里。如果是这种情况,则您引用的变量在全局范围内不存在。引用发布的变量时使用 $_POST 数组。

这在你的脚本顶部应该让它工作:

$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
// etc...
于 2012-06-30T22:36:31.953 回答
0

我看不到 $name、$email 等的来源。您是否将 $_POST 数据分配给您的变量?这边走

$name = $_POST['name'] 
$email = $_POST['email'] 
$phone = $_POST['phone'] 
$comments = $_POST['comments']

//etc
于 2012-06-30T22:40:30.717 回答
0

您需要从 $_POST 数组中提取变量以便在 PHP 中使用它们。您的 HTML 很好,但要检索表单提交,您必须使用类似于以下的代码:

$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
于 2012-06-30T22:55:27.290 回答