2形成相同的页面问题 [英] 2 forms same page issue

查看:60
本文介绍了2形成相同的页面问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想在1页上有2个表格,我复制了第1个表格并给了它另一个ID,但由于某种原因,第2个表格验证/成功消息不会出现在表单页面中,而是出现在空白页面中。然而,该表格已成功发送。



 <! -    联系表单   - >   
< 表格 id = contactform2 action = contact_form2 .php 方法 = 发布 > < br >
&l t; div class = col-md-6 >
< div class = row >

< div class = col-sm-12 >
< div class = form-group wow fadeInUp data-wow-delay = 0.2s >
< label class = sr-only > 您的姓名< / label >
< input type = text id = name2 name = name2 class = 表单控件 占位符 = 您的姓名 >
< / div >
< / div >

< div class = col-sm-12 >
< div class = form-group wow fadeInUp data-wow-delay = 0.4s >
< label class = sr-only > 您的电子邮件< / label &G t;
< 输入 type = email id = email2 名称 = email2 class = 表单控制 占位符 = 您的电子邮件 < span class =code-keyword>>

< / d iv >
< / div >

< div class = col-sm-12 >
< div class = form-group wow fadeInUp data-wow-delay = 0.8s >
< 升abel class = sr-only > 按摩< / label >
< textarea class = form-control textarea id = message2 name = message2 = 5 占位符 = 按摩 > < / textarea >
< / div >
< / div > ;

< div class = col -sm-12 >
< 二v class = form-group wow fadeInUp data-wow-delay = 1s >
< 按钮 类型 = 提交 id = send2 class = btn btn-default > 发​​送按摩< / button >
< a id = about href = contact_form2.php title = 摘要 > blblblb < / a >
< < span class =code-leadattribute> / div >
< / div >

< / div class = row >
< / div class = col-md-6 >

< / form >
< div id = 响应 > < / div >
<! - /.contact form - >





和php脚本:



 <?php  

// 清理输入值
foreach($ _ POST as $ key => $ value $ {b $ b if(ini_get(' magic_quotes_gpc'))
$ _POST [$ key] = stripslashes($ _ POST [$ key]);

$ _POST [$ key] = htmlspecialchars(strip_tags($ _ POST [$ key]));
}

// 将输入值分配给变量以便于参考
$ name = $ _POST [ ];
$ email = $ _POST [ email ];
$ message = $ _POST [ 消息];

// 测试错误输入值
$ errors = array();
if(strlen($ name)< 2){
if(!$ name){
$ errors [] = 您必须输入名称。;
} else {
$ errors [] = 名称必须至少为2个字符。;
}
}
if(!$ email){
$ errors [] = 您必须输入电子邮件。;
} else if(!validEmail($ email)){
$ errors [] = 您必须输入有效的电子邮件。;
}
if(strlen($ message)< 10){
if(!$ message){
$ errors [] = 您必须输入一条消息。;
} else {
$ errors [] = 消息必须至少10个字符。;
}
}

if($ errors){
// 输出错误并因故障消息而死亡
$ errortext = ;
foreach($ errors as $ error){
$ errortext 。= < span class =code-string>
< li>。$ error。 < / li>;
}
die( < span class ='failure'>发生以下错误:< ul> $ errortext < / UL>< /跨度> 中);
}

// 发送电子邮件
$ to = Lexi@gmail.com;
$ subject = 联系表格:$名称;
$ message = $ message< /跨度>;
$ headers = 来自:$ email ;

邮件($ to,$ subject,$ message,$ headers);

// 成功消息死亡
die(< span class =code-string>
< span class ='success'>成功!您的邮件已发送。< / span>);

// 检查
<的函数span class =code-comment> //
电子邮件有效
function validEmail($ email)
{
$ isValid = true;
$ atIndex = strrpos($ email, @);
if (is_bool($ atIndex)&&!$ atIndex)
{
$ isValid = false;
}
else
{
$ domain = substr($ email,$ atIndex + 1);
$ local = substr($ email,0,$ atIndex);
$ localLen = strlen($ local);
$ domainLen = strlen($ domain);
if ($ localLen< 1 || $ localLen > 64)
{
// 超出本地零件长度
$ isValid = false;
}
其他 if ($ domainLen< 1 || $ domainLen > 255)
{
// 超出域名部分长度
$ isValid = false;
}
else if ($ local [0] == ' 。' || $ local [$ localLen-1] == ' 。'
{
// 本地部分以'。'开头或结尾。
$ isValid = false;
}
else if (preg_match(' / \\。\\ ./',$ local))
{
// 本地部分有两个连续的点
$ isValid = false;
}
else if (!preg_match(' / ^ [A-Za-z0-9 \\-\\。] + $ /',$ domain ))
{
// 字符在域名部分无效
$ isValid = false;
}
else if (preg_match(' / \\.\\ ./',$ domain))
{
// 域部分有两个连续的点
$ isValid = false;
}
else if(!preg_match(' / ^(\\\\ | [A-ZA-Z0-9#%&安培;!?`_ = \\ / $ \'* + ^ {} |〜 .-])+ $ /'
str_replace( \\\ \ ,$ local)))
{
// 字符在本地部分无效,除非
// 引用本地部分
if (!preg_match (' / ^(\\\\| [^])+$ /
str_replace( \\\\ ,$ local)))
{
$ isValid = false;
}
}
如果($ isValid&&!(checkdnsrr($ domain, MX)|| checkdnsrr($ domain, A)))
{
// 在DNS中找不到域
$ isValid = false;
}
}
返回 $ isValid ;
}

?>





我尝试了什么:



我试图改变第二种形式的所有字段名称和ID(name2,email2) )

我试图将php脚本的结尾名称复制到contact_form2.php并将第二个表格指向它。

解决方案

_POST < span class =code-keyword> as


key =>


value){
if(ini_get(' magic_quotes_gpc'))

Hi,

I want to have 2 forms on 1 page, I had duplicated the 1st form and gave it an other ID but for some reason the 2nd forms validation / success messages do not appear in the form page but a blank page. The form is send successfully however.

<!-- contact form -->
<form id="contactform2" action="contact_form2.php" method="post"><br>
<div class="col-md-6">
<div class="row">

<div class="col-sm-12">
<div class="form-group wow fadeInUp" data-wow-delay="0.2s">
<label class="sr-only">Your Name</label>
<input type="text" id="name2" name="name2" class="form-control" placeholder="Your Name">
</div>
</div>

<div class="col-sm-12">
<div class="form-group wow fadeInUp" data-wow-delay="0.4s">
<label class="sr-only">Your Email</label>
<input type="email" id="email2" name="email2" class="form-control" placeholder="Your Email">
</div>
</div>

<div class="col-sm-12 ">
<div class="form-group wow fadeInUp" data-wow-delay="0.8s">
<label class="sr-only">Massage</label>
<textarea class="form-control textarea" id="message2" name="message2" rows="5" placeholder="Massage"></textarea>
</div>
</div>

<div class="col-sm-12">
<div class="form-group wow fadeInUp" data-wow-delay="1s">
<button type="submit" id="send2" class="btn btn-default ">Send Massage</button>
<a id="about" href="contact_form2.php" title="summary">blblblb</a>
</div>
</div>

</div class="row">      
</div class="col-md-6">

</form>
<div id="response"></div>
<!-- /.contact form -->



And the php script:

<?php

// Clean up the input values
foreach($_POST as $key => $value) {
	if(ini_get('magic_quotes_gpc'))
		$_POST[$key] = stripslashes($_POST[$key]);
	
	$_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
}

// Assign the input values to variables for easy reference
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];

// Test input values for errors
$errors = array();
if(strlen($name) < 2) {
	if(!$name) {
		$errors[] = "You must enter a name.";
	} else {
		$errors[] = "Name must be at least 2 characters.";
	}
}
if(!$email) {
	$errors[] = "You must enter an email.";
} else if(!validEmail($email)) {
	$errors[] = "You must enter a valid email.";
}
if(strlen($message) < 10) {
	if(!$message) {
		$errors[] = "You must enter a message.";
	} else {
		$errors[] = "Message must be at least 10 characters.";
	}
}

if($errors) {
	// Output errors and die with a failure message
	$errortext = "";
	foreach($errors as $error) {
		$errortext .= "<li>".$error."</li>";
	}
	die("<span class='failure'>The following errors occured:<ul>". $errortext ."</ul></span>");
}

// Send the email
$to = "Lexi@gmail.com";
$subject = "Contact Form: $name";
$message = "$message";
$headers = "From: $email";

mail($to, $subject, $message, $headers);

// Die with a success message
die("<span class='success'>Success! Your message has been sent.</span>");

// A function that checks to see if
// an email is valid
function validEmail($email)
{
   $isValid = true;
   $atIndex = strrpos($email, "@");
   if (is_bool($atIndex) && !$atIndex)
   {
      $isValid = false;
   }
   else
   {
      $domain = substr($email, $atIndex+1);
      $local = substr($email, 0, $atIndex);
      $localLen = strlen($local);
      $domainLen = strlen($domain);
      if ($localLen < 1 || $localLen > 64)
      {
         // local part length exceeded
         $isValid = false;
      }
      else if ($domainLen < 1 || $domainLen > 255)
      {
         // domain part length exceeded
         $isValid = false;
      }
      else if ($local[0] == '.' || $local[$localLen-1] == '.')
      {
         // local part starts or ends with '.'
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $local))
      {
         // local part has two consecutive dots
         $isValid = false;
      }
      else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
      {
         // character not valid in domain part
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $domain))
      {
         // domain part has two consecutive dots
         $isValid = false;
      }
      else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
                 str_replace("\\\\","",$local)))
      {
         // character not valid in local part unless 
         // local part is quoted
         if (!preg_match('/^"(\\\\"|[^"])+"$/',
             str_replace("\\\\","",$local)))
         {
            $isValid = false;
         }
      }
      if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
      {
         // domain not found in DNS
         $isValid = false;
      }
   }
   return $isValid;
}

?>



What I have tried:

I have tried to change all the field names and ID's in the second form (name2, email2)
I have tried to copy the php script end name it contact_form2.php and pointed the 2nd form to it.

解决方案

_POST as


key =>


value) { if(ini_get('magic_quotes_gpc'))


这篇关于2形成相同的页面问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆