首页 > 解决方案 > 将一个表单的数据从一个页面和另一个表单的第二页一起传递到电子邮件

问题描述

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

表格 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.';
            }
    }

}

?>

标签: phpformsemail

解决方案


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

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

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

<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>

推荐阅读