Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用php在多个页面和电子邮件中传递复选框值_Javascript_Php_Jquery_Html_Email - Fatal编程技术网

Javascript 使用php在多个页面和电子邮件中传递复选框值

Javascript 使用php在多个页面和电子邮件中传递复选框值,javascript,php,jquery,html,email,Javascript,Php,Jquery,Html,Email,您好,我正在创建一个简单的宣传册申请表,以捕获用户的品牌和价格信息以及他们的电子邮件id。我为三个页面创建了代码(Page1.php用于品牌选择,Page2.php用于价格范围和电子邮件地址。我在下一个页面中获得了Page1.php的用户选择值,但在邮件页面中没有获得值(我需要在此处收集这两个页面值并提交到电子邮件)。请查找下面的页面代码。请帮助 page1.php 你想买哪辆车? 法拉利 梅赛德斯 布加迪 检查每页下面的代码 第1页 你想买哪辆车? 法拉利 梅赛德斯 布加迪 第2页

您好,我正在创建一个简单的宣传册申请表,以捕获用户的品牌和价格信息以及他们的电子邮件id。我为三个页面创建了代码(Page1.php用于品牌选择,Page2.php用于价格范围和电子邮件地址。我在下一个页面中获得了Page1.php的用户选择值,但在邮件页面中没有获得值(我需要在此处收集这两个页面值并提交到电子邮件)。请查找下面的页面代码。请帮助

page1.php


你想买哪辆车?
法拉利
梅赛德斯
布加迪


检查每页下面的代码

第1页


你想买哪辆车?
法拉利
梅赛德斯
布加迪

第2页

在本页中,我使用内爆函数将数组转换为字符串

<html>
<body  bgcolor="#fff" text="#000" >

<div id="firstpage-value" style="border:1px solid #000;">
<h4>Selected Brand</h4>
<?php
if(isset($_POST['car_brand']))
{   
    $count=count($_POST['brand']);
    for($i=0;$i<$count;$i++)
    {
        echo $_POST['brand'][$i]." ";
    }
    $brand = implode("," ,$_POST['brand']);
}
?>
</div>

<form method="post" action="mail.php">
<p>Choose a Price Range<P>
<TABLE border="1" width="500">
<TR ><TD><input type="checkbox" value ="under20k"  name="price[]"><TD>Under $20K</td></TR>
<TR><TD><input type="checkbox" value ="35-85k"  name="price[]"><TD>$35K-$85K</td></TR>
<TR><TD><input type="checkbox" value ="over85k"  name="price[]"><TD>Over $85K</td></TR>
</TABLE>
<input type="text" name="email" value="email" />
<input type="hidden" value="1" name="car_price" >
<p>
<input type="submit" value="Submit" >

<input type="hidden" name="brand" value="<?php  echo $brand; ?>">
</form>
</body>
</html>

精选品牌
选择一个价格范围
2万美元以下
3.5万至8.5万美元
超过8.5万美元


这里的信息太多,无法发表评论。有几件事你可以记住。首先:

检查POST请求 仔细检查处理请求的页面上是否有有效的POST请求,现在您只需假设第2页上有任何POST请求。这样,您就可以确保有您需要的数据。例如,在
page1.php
上命名您的按钮:
,现在您可以在第2页验证是否按下此按钮:

if( isset( $_POST['step1'] )) 
{
    // Process your code, otherwise return to page1
}
验证发送到下一页的数据 通过检查发送的数据,确保您从上一页接收到正确的数据。您可以通过一个简单的
var\u dump()
。如果将var\u dump()包装在

要将此字符串返回数组,可以使用
explode(“,”,$brands);

全部应用并调试
应用所有这些东西,在每篇文章中验证您的请求,并调试出错的地方和地方。这些简单的步骤将使您的脚本很快运行起来。您的脚本还有很多需要学习和改进的地方。但现在让我们通过这些提示来说明问题。

问题在page2.php上
在这里,您正在将数组转换为第
行的字符串,非常感谢Joshua-Pendo和Suyog。如果答案正确,则表示同意该答案
<?php 



/* Subject and email variables */

$emailsSubject = 'Brochure Request';
$thanks = 'Thank you for requesting Brochure';
$webMaster  = 'mailsample@gmail.com';
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";

//Get the input.
 $email = $_POST['email'];
$brand = $_POST['brand'];
$price = implode(",",$_POST['price']); 


$body = '
<p>A user has been submitted "Request Brochure" form with the following info.</p>
<table width="600" border="1" >
      <tr>
      <th width="556" height="37" align="left"><h2>Which car you want to buy?</h2></th>
      <th width="268" style="border-bottom:1px solid #ccc; ">'.$brand.'</th>
    </tr>
    <tr>
      <th width="556" height="37" align="left"><h2>Choose price range</h2></th>
      <th width="268" style="border-bottom:1px solid #ccc; ">'.$price.'</th>
    </tr>

    <tr>
      <th width="556" height="37" align="left"><h2>Email Address</h2></th>
      <th width="268" style="border-bottom:1px solid #ccc; ">'.$email.'</th>
    </tr>   
    ';


    $headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$headers .= 'Cc:'. $email . "\r\n";
$reply = "";

/* This is what sends the email */
$success = mail($webMaster, $body, $headers, "-f $email");


/* Results Rendered as Html */



header('location:thankyou.php');exit;
?>
if( isset( $_POST['step1'] )) 
{
    // Process your code, otherwise return to page1
}
if( isset( $_POST['step1'] )) 
{
    echo '<pre>'; var_dump($_POST); echo '</pre>';
}
if( count($_POST['brand']) > 0 ) {
    $brands = implode(",", $_POST['brand']);  // returns: ferrari,mercedes,bugatti
}
$brand = '';
if(isset($_POST['brand']))
{   
    $brand = implode("," ,$_POST['brand']);
}
<input type="hidden" name="brand" value="<?php echo $brand; ?>">