我想包具有相同的页面验证,但外部处理此联系人/报价表。我已经设置了一个变量来进行表单操作,当表单验证时,变量/网址从同一页面更改为处理页面。然而,它走的是两条点击提交按钮,以处理后的形式所需的所有领域都被填充:所有必填字段将填写,我点击提交,页面重新加载与保存的数据变量,然后当我点击提交agin,它终于完成,发送电子邮件并加载谢谢页面。我在这里搜索了这些帖子,尝试了很多东西,但还没有找到解决方案。我绝对不是一个PHP专家,还是个新手,所以这可能不是实现这一目标的最佳方式,但我会很感激如何完成这件事的任何想法。这里是我的:PHP表单验证与外部处理
<?php
....
if (empty($Name) && empty($Company) && empty($Address1) && empty($City) && empty($State) && empty($Phone))
{
echo '<p class="tan">The fields marked with an * are required.</p>';
$Process = 'samepageurl';
}
/*else if (empty($Name) || is_numeric($Name))
{
echo '<p class="tan"><b>Please enter your name.</b></p>';
}*/
else if (empty($Company) || is_numeric($Company))
{
echo '<p class="tan"><b>Please enter your company name.</b></p>';
$Process = 'samepageurl';
}
else if (empty($Address1) || is_numeric($Address1))
{
echo '<p class="tan"><b>Please enter your address.</b></p>';
$Process = 'samepageurl';
}
else if (empty($City) || is_numeric($City))
{
echo '<p class="tan"><b>Please enter your city.</b></p>';
$Process = 'samepageurl';
}
else if (empty($State) || is_numeric($State))
{
echo '<p class="tan"><b>Please enter your state.</b></p>';
$Process = 'samepageurl';
}
else if (empty($Phone) || ctype_alpha($Phone))
{
echo '<p class="tan"><b>Please enter your phone number.</b></p>';
$Process = 'samepageurl';
}
else if (strlen($Phone) < 10 || strlen($Phone) > 12 || ctype_alpha($Phone) || ctype_space($Phone))
{
echo '<p class="tan"><b>Please enter a phone number with an area code.</b></p>';
$Process = 'samepageurl';
}
else if (isset($Name) && isset($Company) && isset($Address1) && isset($City) && isset($State) && isset($Phone))
{
$Process = 'processingurl';
}
?>
<form action="<?php echo $Process; ?>" method="post" class="print" >
<p><input type="hidden" name="recipient" value="[email protected]"/>
<input type="hidden" name="subject" value="Web Site Response"/>
<input type="hidden" name="redirect" value="thankyou.html"/></p>
... form fields ...
</form>
谢谢你提前!
这是你的全部代码吗?看起来您并不像您指定您的$ _POST变量,例如'$名称= $ _ POST [“名”];' – romo 2013-03-20 22:04:22
你最好检查这对客户方在我看来的JavaScript。现在您已经通过验证重新回到了服务器端。如果验证失败,您也可以重新导向到表单页面。但不是做事的最佳方式。 – Daniel 2013-03-20 22:06:18
你绝对应该做的客户端验证像丹尼尔说,但服务器端验证也是不错的。看到这里的问题的详细信息,建立一个非常简单的形式与验证:http://stackoverflow.com/questions/12158229/php-form-submit – jacobangel 2013-03-20 22:21:07