将一个表单中的数据从一页和另一表单中的数据一起传递到电子邮件

时间:2018-10-20 22:08:25

标签: php forms email

我有第一页的表格和第二页的表格。我想要的是两种形式都必须在一封电子邮件中一起发送数据。我试图从一种形式获取信息,然后将其发布到另一种形式所在的变量的另一页中,然后将其发送到电子邮件中。但是当我发送第二个表格时,表格1的第一页中的数据丢失了。

表格1第一页

                <form action="https://investorsolution.com.au/commercial-loan-form-slider/" method="post">
                <div class="refinance_input">
                <input type="text" placeholder="Loan Amount" id="comaperror" class="number" name="how_long_do_you_need_the_loan_for" required/>
                </div>
                <div class="refinance_submit">
                <input type="submit" class="comapnext" value="APPLY NOW" />
                </div>
                </form>

表格2第2页

<form action="" method="post" enctype="multipart/form-data">
        <div id="msform">
            <!-- progressbar -->
            <ul id="progressbar">
                <li class="active"></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>

            <!-- fieldsets -->
            <fieldset>
                <!-- Success message -->
                <h1 style="color: #87C550;
                    font-size: 25px;
                    line-height: 50px;
                    font-family: 'Ubuntu';
                    font-weight: 700;">
                            <?php 
                                if(isset($success)){
                                    echo $success;
                                }
                                if(isset($error)){
                                    echo $error;
                                }
                            ?>
                </h1>
                <h2 class="fs-title">Get an Easy Access to Funding</h2>
                <h3 class="fs-subtitle">Are you trading for at least 6 months?</h3>
                <p class="comfmsg1"></p>
                    <div class="form_radio_button_custom_two">
                          <input type="radio" name="trading_for_at_least_6_months" value="Yes" id="6_months_yes"/>
                          <label for="6_months_yes" style="padding: 20px 80px !important;">Yes</label>
                        </div>
                        <div class="form_radio_button_custom_two">  
                            <input type="radio" name="trading_for_at_least_6_months" value="No" id="6_months_no"/>
                            <label for="6_months_no" style="padding: 20px 80px !important;">No</label>
                        </div>

                <input type="button" name="next" class="next_extra_per comfnext1 action-button" value="Next" />
            </fieldset>

            <fieldset>
                <br>
                <br>
                <br>
                <h3 class="fs-subtitle">Do you have a revenue of minimum $10,000 per month?</h3>
                <p class="comfmsg2"></p>
                        <div class="form_radio_button_custom_two">
                          <input type="radio" name="revenue_of_minimum_10000" value="Yes" id="revenue_minimum_yes"/>
                          <label for="revenue_minimum_yes" style="padding: 20px 80px !important;">Yes</label>
                        </div>
                        <div class="form_radio_button_custom_two">  
                            <input type="radio" name="revenue_of_minimum_10000" value="Yes" id="revenue_minimum_no"/>
                            <label for="revenue_minimum_no" style="padding: 20px 80px !important;">No</label>
                        </div>

                <input type="button" name="next" class="next_extra_per comfnext2 action-button" value="Next" />
                <input type="button" name="previous" class="previous_extra_per previous action-button" value="Back" />
            </fieldset>

            <fieldset>
                <br>
                <br>
                <br>
                <h3 class="fs-subtitle">Is this loan going to be used for any business purpose?</h3>
                <p class="comfmsg3"></p>
                        <div class="form_radio_button_custom_two">
                          <input type="radio" name="used_for_any_business_purpose" value="Yes" id="business_purpos_yes"/>
                          <label for="business_purpos_yes" style="padding: 20px 80px !important;">Yes</label>
                        </div>
                        <div class="form_radio_button_custom_two">  
                            <input type="radio" name="used_for_any_business_purpose" value="Yes" id="business_purpos_no"/>
                            <label for="business_purpos_no" style="padding: 20px 80px !important;">No</label>
                        </div>

                <input type="button" name="next" class="next_extra_per comfnext3 action-button" value="Next" />
                <input type="button" name="previous" class="previous_extra_per previous action-button" value="Back" />
            </fieldset>

        <fieldset style="width:100%;">
                <h2 class="fs-title">Get an Easy Access to Funding</h2>
                <h3 class="fs-subtitle">How long are you in the Business?</h3>
                <p class="comfmsg4"></p>
                        <div class="form_radio_button_custom_two">
                          <input type="radio" name="how_long_are_you_in_the_business" value="Less than 6 months" id="less_than_6_months" />
                          <label for="less_than_6_months" style="padding: 20px 5px !important;">Less than 6 months </label>
                        </div>
                        <div class="form_radio_button_custom_two">  
                            <input type="radio" name="how_long_are_you_in_the_business" value="6-12 months" id="6_12_months"/>
                            <label for="6_12_months" style="padding: 20px 5px !important;">6-12 months</label>
                        </div>
                        <div class="form_radio_button_custom_two">
                          <input type="radio" name="how_long_are_you_in_the_business" value="less than 1 year" id="less_than_1_year"/>
                          <label for="less_than_1_year" style="padding: 20px 5px !important;">less than 1 year</label>
                        </div>
                        <div class="form_radio_button_custom_two">  
                            <input type="radio" name="how_long_are_you_in_the_business" value="More than 1 year" id="more_than_1_year"/>
                            <label for="more_than_1_year" style="padding: 20px 5px !important;">More than 1 year</label>
                        </div>

                <input type="button" name="next" class="next_extra_per comfnext4 action-button" value="Next" />
                <input type="button" name="previous" class="previous_extra_per previous action-button" value="Back" />
            </fieldset>

        <fieldset>
                <h3 class="fs-subtitle">What is your First Name?</h3>
                <p class="msgc5"></p>
                <input type="text" name="con_name" class="text_input" id="error5">
                <br />


                <!-- Button Next/Back -->
                <input type="button" name="previous" class="previous action-button" value="Back" style="margin-left: 28%;"/>
                <input type="button5" name="next" class="next5 action-button" value="Next" style="margin-right: 28%;" />
        </fieldset>

        <fieldset>
                <h3 class="fs-subtitle">Your Phone Number</h3>
                <p class="msgc6"></p>
                <input type="text" name="con_phone" class="text_input" id="errorc6">
                <br />

                <!-- Button Next/Back -->
                <input type="button" name="previous" class="previous action-button" value="Back" style="margin-left: 28%;"/>
                <input type="button" name="next" class="nextc6 action-button" value="Next" style="margin-right: 28%;" />
        </fieldset>

        <fieldset>
                <h3 class="fs-subtitle">Your Email Address</h3>
                <p class="msgc7"></p>
                <input type="email" name="con_email" class="text_input" id="errorc7">
                <br />

                <!-- Button Next/Back -->
                <input type="button" name="previous" class="previous action-button" value="Back" style="margin-left: 28%;"/>
                <input type="button" name="next" class="nextc7 action-button" value="Next" style="margin-right: 28%;" />
        </fieldset>


        <fieldset>
                <h3 class="fs-subtitle">What is the Business Trading Name?</h3>
                <p class="msgc8"></p>
                <input type="text" name="trading_name" class="text_input" id="errorc8">
                <br>
                <!-- Button Next/Back -->
                <input type="button" name="previous" class="previous action-button" value="Back" style="margin-left: 28%;"/>
                <input type="button" name="next" class="nextc8 action-button" value="Next" style="margin-right: 28%;" />
        </fieldset>


        <fieldset>
                <h3 class="fs-subtitle">What is Your Address?</h3>
                <p class="msgcb"></p>
                <input type="text" name="your_address" class="text_input"id="errorcb">
                <br>
                <!-- Button Next/Back -->
                <input type="button" name="previous" class="previous action-button" value="Back" style="margin-left: 28%;"/>
                <input type="submit" name="con_submit" class="submit action-button" value="Submit" style="margin-right: 28%;" />
        </fieldset>

            <div>
        </form>

表格2的php代码

<?php
if(isset($_POST['con_submit'])){


    $trading_for_at_least_6_months = $_POST['trading_for_at_least_6_months'];
    $revenue_of_minimum_10000 = $_POST['revenue_of_minimum_10000'];
    $used_for_any_business_purpose = $_POST['used_for_any_business_purpose'];
    $how_long_are_you_in_the_business = $_POST['how_long_are_you_in_the_business'];
    $how_long_do_you_need_the_loan_for = $_REQUEST['how_long_do_you_need_the_loan_for'];
    $how_long_do_you_need_the_loan_for = $_POST['how_long_do_you_need_the_loan_for'];
    $con_name = $_POST['con_name'];
    $con_phone = $_POST['con_phone'];
    $con_email = $_POST['con_email'];
    $trading_name = $_POST['trading_name'];
    $your_address = $_POST['your_address'];

    if(!empty($con_name) && !empty($con_email) && !empty($con_phone)){


            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

        $con_message = "<table border='1' width='100%'>
            <tr>
            <td width='25%'>Subject</td>
            <td>Commercial Form</td>
            </tr>
            <tr>
            <td width='25%'>Are you trading for at least 6 months?</td>
            <td>$trading_for_at_least_6_months</td>
            </tr>
            <tr>
            <td width='25%'>Do you have a revenue of minimum $ 10,000 per month?</td>
            <td>$revenue_of_minimum_10000</td>
            </tr>
            <tr>
            <td width='25%'>Is this loan going to be used for any business purpose?</td>
            <td>$used_for_any_business_purpose</td>
            </tr>
            <tr>
            <td width='25%'>How long are you in the Business?</td>
            <td>$how_long_are_you_in_the_business</td>
            </tr>
            <tr>
            <td width='25%'>How long do you need the loan for?</td>
            <td>$how_long_do_you_need_the_loan_for</td>
            </tr>
            <tr>
            <td width='25%'>What is your First Name?</td>
            <td>$con_name</td>
            </tr>
            <tr>
            <td width='25%'>Your Phone Number</td>
            <td>$con_phone</td>
            </tr>
            <tr>
            <td width='25%'>Your Email Address</td>
            <td>$con_email</td>
            </tr>
            <tr>
            <td width='25%'>What is the Business Trading Name?</td>
            <td>$trading_name</td>
            </tr>
            <tr>
            <td width='25%'>What is Your Address?</td>
            <td>$your_address</td>
            </tr>
            </table>";

        $mailsent = mail('loans@investorsolution.com.au,xdtaufeeq@gmail.com', 'Commercial Loan Form', $con_message, $headers);

            if($mailsent){
                $success = 'Your mail has been sent successfully.';
            }else{
                $error = 'Your message has not been sent.';
            }
    }

}

?>

3 个答案:

答案 0 :(得分:0)

在这种情况下,有3种方法:

选项1:

  

您将表格1中的数据存储到会话或数据库中。并仅在生成电子邮件时检索存储的输入。

选项2:

  

您将表单1上的输入作为表单2上的预填隐藏输入字段发送回用户,以便第二个发布/获取请求将同时拥有这两种表单中的所有数据。

选项3:

  

将两种形式结合在一起。

答案 1 :(得分:0)

解决了,谢谢奥马尔·塔尼(Omar Tani)。我没有正确填写表格。找到并解决了

<input type="text" name="how_long_do_you_need_the_loan_for" value="<?=htmlspecialchars($_POST['how_long_do_you_need_the_loan_for'])?>" style="display:none" />

答案 2 :(得分:0)

要将数据从表格1传递到表格2,然后将在表格1中提交的数据也包括在表格2中,您需要:

  • 将数据从表格1传递到表格2(您当前正在正确执行)
  • 将表单1中的数据也包含在表单2中的隐藏输入中(将用户输入转换为html实体以避免安全问题)

还请注意,您不需要使用type="text"创建输入,然后使用style="display:none;"。您可以使用type="hidden"创建一个inout,浏览器会自动将其隐藏给用户,如下所示:

<input type="hidden" name="how_long_do_you_need_the_loan_for" value="<?= htmlspecialchars($_POST['how_long_do_you_need_the_loan_for'])?>" />

在您的情况下,表格2应该如下:

<form action="" method="post" enctype="multipart/form-data">

    <input type="hidden" name="how_long_do_you_need_the_loan_for" value="<?= htmlspecialchars($_POST['how_long_do_you_need_the_loan_for'])?>" />

    <div id="msform">
        <!-- progressbar -->
        <ul id="progressbar">
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>

        <!-- fieldsets -->
        <fieldset>
            <!-- Success message -->
            <h1 style="color: #87C550;
                font-size: 25px;
                line-height: 50px;
                font-family: 'Ubuntu';
                font-weight: 700;">
                        <?php 
                            if(isset($success)){
                                echo $success;
                            }
                            if(isset($error)){
                                echo $error;
                            }
                        ?>
            </h1>
            <h2 class="fs-title">Get an Easy Access to Funding</h2>
            <h3 class="fs-subtitle">Are you trading for at least 6 months?</h3>
            <p class="comfmsg1"></p>
                <div class="form_radio_button_custom_two">
                      <input type="radio" name="trading_for_at_least_6_months" value="Yes" id="6_months_yes"/>
                      <label for="6_months_yes" style="padding: 20px 80px !important;">Yes</label>
                    </div>
                    <div class="form_radio_button_custom_two">  
                        <input type="radio" name="trading_for_at_least_6_months" value="No" id="6_months_no"/>
                        <label for="6_months_no" style="padding: 20px 80px !important;">No</label>
                    </div>

            <input type="button" name="next" class="next_extra_per comfnext1 action-button" value="Next" />
        </fieldset>

        <fieldset>
            <br>
            <br>
            <br>
            <h3 class="fs-subtitle">Do you have a revenue of minimum $10,000 per month?</h3>
            <p class="comfmsg2"></p>
                    <div class="form_radio_button_custom_two">
                      <input type="radio" name="revenue_of_minimum_10000" value="Yes" id="revenue_minimum_yes"/>
                      <label for="revenue_minimum_yes" style="padding: 20px 80px !important;">Yes</label>
                    </div>
                    <div class="form_radio_button_custom_two">  
                        <input type="radio" name="revenue_of_minimum_10000" value="Yes" id="revenue_minimum_no"/>
                        <label for="revenue_minimum_no" style="padding: 20px 80px !important;">No</label>
                    </div>

            <input type="button" name="next" class="next_extra_per comfnext2 action-button" value="Next" />
            <input type="button" name="previous" class="previous_extra_per previous action-button" value="Back" />
        </fieldset>

        <fieldset>
            <br>
            <br>
            <br>
            <h3 class="fs-subtitle">Is this loan going to be used for any business purpose?</h3>
            <p class="comfmsg3"></p>
                    <div class="form_radio_button_custom_two">
                      <input type="radio" name="used_for_any_business_purpose" value="Yes" id="business_purpos_yes"/>
                      <label for="business_purpos_yes" style="padding: 20px 80px !important;">Yes</label>
                    </div>
                    <div class="form_radio_button_custom_two">  
                        <input type="radio" name="used_for_any_business_purpose" value="Yes" id="business_purpos_no"/>
                        <label for="business_purpos_no" style="padding: 20px 80px !important;">No</label>
                    </div>

            <input type="button" name="next" class="next_extra_per comfnext3 action-button" value="Next" />
            <input type="button" name="previous" class="previous_extra_per previous action-button" value="Back" />
        </fieldset>

    <fieldset style="width:100%;">
            <h2 class="fs-title">Get an Easy Access to Funding</h2>
            <h3 class="fs-subtitle">How long are you in the Business?</h3>
            <p class="comfmsg4"></p>
                    <div class="form_radio_button_custom_two">
                      <input type="radio" name="how_long_are_you_in_the_business" value="Less than 6 months" id="less_than_6_months" />
                      <label for="less_than_6_months" style="padding: 20px 5px !important;">Less than 6 months </label>
                    </div>
                    <div class="form_radio_button_custom_two">  
                        <input type="radio" name="how_long_are_you_in_the_business" value="6-12 months" id="6_12_months"/>
                        <label for="6_12_months" style="padding: 20px 5px !important;">6-12 months</label>
                    </div>
                    <div class="form_radio_button_custom_two">
                      <input type="radio" name="how_long_are_you_in_the_business" value="less than 1 year" id="less_than_1_year"/>
                      <label for="less_than_1_year" style="padding: 20px 5px !important;">less than 1 year</label>
                    </div>
                    <div class="form_radio_button_custom_two">  
                        <input type="radio" name="how_long_are_you_in_the_business" value="More than 1 year" id="more_than_1_year"/>
                        <label for="more_than_1_year" style="padding: 20px 5px !important;">More than 1 year</label>
                    </div>

            <input type="button" name="next" class="next_extra_per comfnext4 action-button" value="Next" />
            <input type="button" name="previous" class="previous_extra_per previous action-button" value="Back" />
        </fieldset>

    <fieldset>
            <h3 class="fs-subtitle">What is your First Name?</h3>
            <p class="msgc5"></p>
            <input type="text" name="con_name" class="text_input" id="error5">
            <br />


            <!-- Button Next/Back -->
            <input type="button" name="previous" class="previous action-button" value="Back" style="margin-left: 28%;"/>
            <input type="button5" name="next" class="next5 action-button" value="Next" style="margin-right: 28%;" />
    </fieldset>

    <fieldset>
            <h3 class="fs-subtitle">Your Phone Number</h3>
            <p class="msgc6"></p>
            <input type="text" name="con_phone" class="text_input" id="errorc6">
            <br />

            <!-- Button Next/Back -->
            <input type="button" name="previous" class="previous action-button" value="Back" style="margin-left: 28%;"/>
            <input type="button" name="next" class="nextc6 action-button" value="Next" style="margin-right: 28%;" />
    </fieldset>

    <fieldset>
            <h3 class="fs-subtitle">Your Email Address</h3>
            <p class="msgc7"></p>
            <input type="email" name="con_email" class="text_input" id="errorc7">
            <br />

            <!-- Button Next/Back -->
            <input type="button" name="previous" class="previous action-button" value="Back" style="margin-left: 28%;"/>
            <input type="button" name="next" class="nextc7 action-button" value="Next" style="margin-right: 28%;" />
    </fieldset>


    <fieldset>
            <h3 class="fs-subtitle">What is the Business Trading Name?</h3>
            <p class="msgc8"></p>
            <input type="text" name="trading_name" class="text_input" id="errorc8">
            <br>
            <!-- Button Next/Back -->
            <input type="button" name="previous" class="previous action-button" value="Back" style="margin-left: 28%;"/>
            <input type="button" name="next" class="nextc8 action-button" value="Next" style="margin-right: 28%;" />
    </fieldset>


    <fieldset>
            <h3 class="fs-subtitle">What is Your Address?</h3>
            <p class="msgcb"></p>
            <input type="text" name="your_address" class="text_input"id="errorcb">
            <br>
            <!-- Button Next/Back -->
            <input type="button" name="previous" class="previous action-button" value="Back" style="margin-left: 28%;"/>
            <input type="submit" name="con_submit" class="submit action-button" value="Submit" style="margin-right: 28%;" />
    </fieldset>

        <div>
</form>