Javascript 如何使用php提交输入值取决于基于下拉选择显示的输入值

Javascript 如何使用php提交输入值取决于基于下拉选择显示的输入值,javascript,php,html,forms,drop-down-menu,Javascript,Php,Html,Forms,Drop Down Menu,我目前有一个下拉列表的工作代码,可以选择并使用JavaScript显示/隐藏值,具体取决于所选择的内容,如下面的代码所示。我想做的是,根据新的和使用的选择,有三种不同的表单输入。如果您选择used,它将直接进入一个表单,其中包含要输入的输入。如果您选择“新建”,它会弹出另一个下拉列表,您可以在其中选择“租赁”或“购买”,并根据该下拉列表选择另外两个显示的表单。我知道如何使用POST将一个表单提交给php。但是,我的问题是,根据下拉列表,表单会随着不同的输入而变化。如何使用php提交此文件。下面是

我目前有一个下拉列表的工作代码,可以选择并使用JavaScript显示/隐藏值,具体取决于所选择的内容,如下面的代码所示。我想做的是,根据新的和使用的选择,有三种不同的表单输入。如果您选择used,它将直接进入一个表单,其中包含要输入的输入。如果您选择“新建”,它会弹出另一个下拉列表,您可以在其中选择“租赁”或“购买”,并根据该下拉列表选择另外两个显示的表单。我知道如何使用POST将一个表单提交给php。但是,我的问题是,根据下拉列表,表单会随着不同的输入而变化。如何使用php提交此文件。下面是我的代码,有三个文件:newform.php、newform.js和newformprocess.php。再次发送表格,如果它没有改变,我知道该怎么做。我遇到的问题是,表单会根据所选的下拉列表进行更改。非常感谢你的帮助。谢谢大家。还有newformprocess.php文件,我知道它与$\u POST值等看起来不正确。这是我想要使用的代码,所以我缺少它

第一个文件newform.php

<?php include('formProcess.php'); ?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Offer Submission Form</title>
    <link rel="stylesheet" type="text/css" href="css/mystyle.css">
    <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
    <script type="text/javascript" src="js/newForm.js"></script>
  </head>

<body>
 <div class="form-style-10">
        <h2>Please Select Your Offer Type</h2>
  <div class="inner-wrap">

   <form action="newformprocess.php" method="post">

    <label>Dealership Name:<em class="required-star">*</em></label><input id="fin_dealerName" name="input_1" type="text" placeholder="Dealership Name" />

    <label>Which Marketing Medium?<em class="required-star">*</em></label><select id="market" type="select" name="marketing">
        <option id="market1" value="marketpick1">Facebook</option>
        <option id="market2" value="marketpick2">Website Banner</option>
        <option id="market3" value="marketpick3">Radio</option>
        <option id="market4" value="marketpick4">TV</option>
        <option id="market5" value="marketpick5">Email</option>
        <option id="market6" value="marketpick6">Direct Mail</option>
        <option id="market7" value="marketpick7">All Channels</option>
    </select>

    <label>Offer Type?</label><select id="newused" type="select" name="offerType">
        <option id="option_1" value="option1">New</option>
        <option id="option_2" value="option2">Used</option>
    </select>

<div id="new" style="display:none;">
    <label>Type of Purchase?</label><select id="newPick" type="select" name="typeOfPurchase">
        <option id="newPick_1" value="newPick1">Purchased</option>
        <option id="newPick_2" value="newPick2">Leased</option>
    </select>
</div>

    <!--This div section is for when client select puchased as their new opiton....--->
    <div id="purchased" style="display:none;">
        <label>Start Date:<em class="required-star">*</em></label><input id="fin_startDate" name="input_2" type="text" placeholder="01/01/2012"/>
        <label>End Date:<em class="required-star">*</em></label><input id="fin_endDate" name="input_3" type="text" placeholder="05/07/2015"/>
        <label>Year:<em class="required-star">*</em></label><input id="fin_vehicleYear" name="input_4" type="text" placeholder="Vehicle Year"/>
        <label>Make:<em class="required-star">*</em></label><input id="fin_make" name="input_5" type="text" placeholder="Make"/>
        <label>Model:<em class="required-star">*</em></label><input id="fin_model" name="input_6" type="text" placeholder="Model"/>
        <label>Trim:<em class="required-star">*</em></label><input id="fin_trim" name="input_7" type="text" placeholder="Trim of Vehicle"/>
        <label>Model #:<em class="required-star">*</em></label><input id="fin_input_5" name="input_8" type="text" placeholder="14325"/>
        <label>Stock #:<em class="required-star">*</em></label><input id="fin_input_5" name="input_9" type="text" placeholder="1234"/>
        <label>MSRP:<em class="required-star">*</em></label><input id="fin_input_5" name="input_10" type="text" placeholder="$15,995"/>
        <label>Selling Price:<em class="required-star">*</em></label><input id="fin_input_5" name="input_11" type="text" placeholder="$12,895"/>
        <label>Down Payment:<em class="required-star">*</em></label><input id="fin_input_5" name="input_12" type="text" placeholder="$1,000"/>
        <label>$XXX/ Monthly Payment:<em class="required-star">*</em></label><input id="fin_input_5" name="input_13" type="text" placeholder="$198"/>
        <label>Last 6 of VIN:<em class="required-star">*</em></label><input id="fin_input_5" name="input_14" type="text" placeholder="123456"/>
        <label>Rebate:</label><input id="fin_input_5" name="input_15" type="text" placeholder="Rebate on Vehicle"/>
        <label>APR:<em class="required-star">*</em></label><input id="fin_input_5" name="input_16" type="text" placeholder="ARP on Vehicle"/>
        <label>Term:<em class="required-star">*</em></label><input id="fin_input_5" name="input_17" type="text" placeholder="Residual Payment on Vehicle"/>
        <label>Other Notes(Rebate Info, Special Details etc):</label> <textarea id="fin_textArea" name="input_18" placeholder="Notes" rows=2></textarea>
    </div>

    <!--This div section is for when client select leased as their new opiton....--->
    <div id="leased" style="display:none;">
        <label>Start Date:<em class="required-star">*</em></label><input id="fin_startDate" name="input_2" type="text" placeholder="01/01/2012"/>
        <label>End Date:<em class="required-star">*</em></label><input id="fin_endDate" name="input_3" type="text" placeholder="05/07/2015"/>
        <label>Year:<em class="required-star">*</em></label><input id="fin_vehicleYear" name="input_4" type="text" placeholder="Vehicle Year"/>
        <label>Make:<em class="required-star">*</em></label><input id="fin_make" name="input_5" type="text" placeholder="Make"/>
        <label>Model:<em class="required-star">*</em></label><input id="fin_model" name="input_6" type="text" placeholder="Model"/>
        <label>Trim:<em class="required-star">*</em></label><input id="fin_trim" name="input_7" type="text" placeholder="Trim of Vehicle"/>
        <label>Model #:<em class="required-star">*</em></label><input id="fin_input_5" name="input_8" type="text" placeholder="14325"/>
        <label>Stock #:<em class="required-star">*</em></label><input id="fin_input_5" name="input_9" type="text" placeholder="1234"/>
        <label>MSRP:<em class="required-star">*</em></label><input id="fin_input_5" name="input_10" type="text" placeholder="$15,995"/>
        <label>Selling Price:<em class="required-star">*</em></label><input id="fin_input_5" name="input_11" type="text" placeholder="$12,895"/>
        <label>Down Payment:<em class="required-star">*</em></label><input id="fin_input_5" name="input_12" type="text" placeholder="$1,000"/>
        <label>$XXX/ Monthly Payment:<em class="required-star">*</em></label><input id="fin_input_5" name="input_13" type="text" placeholder="$198"/>
        <label>Last 6 of VIN:<em class="required-star">*</em></label><input id="fin_input_5" name="input_14" type="text" placeholder="123456"/>
        <label>Rebate:</label><input id="fin_input_5" name="input_15" type="text" placeholder="Rebate on Vehicle"/>
        <label>Term:<em class="required-star">*</em></label><input id="fin_input_5" name="input_16" type="text" placeholder="ARP on Vehicle"/>
        <label>Residual Value:<em class="required-star">*</em></label><input id="fin_input_5" name="input_17" type="text" placeholder="Residual Payment on Vehicle"/>
        <label>Miles Per Year:<em class="required-star">*</em></label><input id="fin_input_5" name="input_17" type="text" placeholder="Residual Payment on Vehicle"/>
        <label>Other Notes(Rebate Info, Special Details etc):</label> <textarea id="fin_textArea" name="input_18" placeholder="Notes" rows=2></textarea>
    </div>

    <!-- IF users picks USED it will go to this section of the form...-->
    <div id="used" style="display:none;">
        <label>Start Date:<em class="required-star">*</em></label><input id="fin_startDate" name="input_2" type="text" placeholder="01/01/2012"/>
        <label>End Date:<em class="required-star">*</em></label><input id="fin_endDate" name="input_3" type="text" placeholder="05/07/2015"/>
        <label>Year:<em class="required-star">*</em></label><input id="fin_vehicleYear" name="input_4" type="text" placeholder="Vehicle Year"/>
        <label>Make:<em class="required-star">*</em></label><input id="fin_make" name="input_5" type="text" placeholder="Make"/>
        <label>Model:<em class="required-star">*</em></label><input id="fin_model" name="input_6" type="text" placeholder="Model"/>
        <label>Trim:</label><input id="fin_trim" name="input_7" type="text" placeholder="Trim of Vehicle"/>
        <label>Stock #:<em class="required-star">*</em></label><input id="fin_input_5" name="input_9" type="text" placeholder="1234"/>
        <label>Selling Price:<em class="required-star">*</em></label><input id="fin_input_5" name="input_11" type="text" placeholder="$12,895"/>
        <label>Down Payment:<em class="required-star">*</em></label><input id="fin_input_5" name="input_12" type="text" placeholder="$1,000"/>
        <label>APR:<em class="required-star">*</em></label><input id="fin_input_5" name="input_16" type="text" placeholder="ARP on Vehicle"/>
        <label>Term:<em class="required-star">*</em></label><input id="used_term" name="input_14" type="text" placeholder=""/>
        <label>Other Notes(Rebate Info, Special Details etc):</label><textarea id="fin_textArea" name="input_18" placeholder="Notes" rows=2></textarea>
    </div>

        <div class="button-section"><br />
            <input type="submit" name="submit" value="Submit Offer" />
        </div>

    </form>
</body>
  </div>
</div>
</html>
最后一个文件newformprocess.php

<?php 

        if(isset($_POST["submit"]))
        {

            // Checking For Blank Fields....
            if($_POST['offerType']==""|| $_POST['typeOfPurchase'] =="" ||$_POST['marketing']==""||$_POST['input_1']==""||$_POST['input_2']==""||$_POST['input_3']==""||$_POST['input_4']==""||$_POST['input_5']==""||
            $_POST['input_6']==""||$_POST['input_7']==""||$_POST['input_9']==""||$_POST['input_10']==""||$_POST['input_11']==""||$_POST['input_12']==""||$_POST['input_13']==""||$_POST['input_14']=="")
                { 
?>
                    <script>
                        alert("Please complete the text marked with an *.");
                    </script>
<?php
                }

        else{

            $Offer = $_POST['offerType'];
            $typeOfpurchase = $_POST['typeOfPurchase'];
            $Marketing = $_POST['marketing'];
            $Field1 = $_POST['input_1'];
            $Field2 = $_POST['input_2'];
            $Field3 = $_POST['input_3'];
            $Field4 = $_POST['input_4'];
            $Field5 = $_POST['input_5'];
            $Field6 = $_POST['input_6'];
            $Field7 = $_POST['input_7'];
            $Field8 = $_POST['input_8'];
            $Field9 = $_POST['input_9'];
            $Field10 = $_POST['input_10'];
            $Field11 = $_POST['input_11'];
            $Field12 = $_POST['input_12'];
            $Field13 = $_POST['input_13'];
            $Field14 = $_POST['input_14'];
            $Field15 = $_POST['input_15'];
            $Field16 = $_POST['input_16'];
            $Field17 = $_POST['input_17'];
            $message = $_POST['input_18'];
            $message = wordwrap($message, 70);
            $form_content = 
            "What Type of Offer: $Offer
            If your purhcase was new what was your type of purchase: $typeOfpurchase
            Which Marketing Medium: $Marketing
            Dealership Name: $Field1
            Offer Start Date: $Field2
            Offer End Date: $Field3
            Year of Vehicle: $Field4
            Make of Vehicle: $Field5
            Model of Vehicle: $Field6
            Trim of Vehicle: $Field7
            Model # Vehicle: $Field8 
            Stock # of Vehicle: $Field9
            MSRP of Vehicle: $Field10
            Selling Price of Vehicle: $Field11
            Down Payment on Vehicle: $Field12
            XXX/ Month on Vehicle: $Field13
            Last 6 of VIN on Vehicle: $Field14
            Rebate on Vehicle: $Field15
            APR on Vehicle: $Field16 
            Residual Payment on Vehicle: $Field17 
            Other Notes (Rebate Info, Special Details etc): $message";

            $email_subject = "Online Offer Submission Form";

            $arrEmail = array('Jonathan <myemail@myemail.com?>');


                foreach($arrEmail as $key => $email_to)
                mail($email_to, $email_subject, $form_content);

                header('location: http://www.mydealerworld.com/thank-you-for-contacting-dealer-world/');
    }
        }

警告(“请填写标有*的文本”);

您可以通过AJAX请求发送输入值。使用Javascript分配变量后,只需使用ajax请求发送它们。(例如,
var您分配的变量=input.val()

查看更多信息:

您可以通过AJAX请求发送输入值。使用Javascript分配变量后,只需使用ajax请求发送它们。(例如,
var您分配的变量=input.val()

查看更多信息:

如果您提交的字段在页面上没有“存在”,它们将在插入中显示为空白。您还可以使用
isset($\u POST['parameter'])
检查是否存在
$\u POST
。你不能“正常”提交表格吗?恐怕我很难看出这个问题。您是否有不同形式的
action=
URL?@obsidiane感谢您的见解。我甚至没有想到这一点,我的意思是我想知道它们是否会作为空白发送。我想现在唯一的问题是我不希望所有的空白字段都通过电子邮件发送。好的,假设这是一辆二手车,它总共只有12个输入字段,但是,假设新购买的字段有18个,并且一些输入字段是不同的。如何删除要通过电子邮件发送的非相关字段。电子邮件发送部分等,我知道如何做了。我是否可以使用某种类型的catch,以便它只发送所用下拉选择的输入字段。@ObsidManager基本上我想我说的是,当我确保字段不为空,并将$_POST['value']存储到一个变量中时,我是否会像上面在newformprocess.php文件中所说的那样,以正常方式执行此操作。不管表单在什么时候被提交,比如说其中一个存储到变量的$\u POST,如果它在$\u POST['value']中没有任何内容,那么它将是空的。对不起,希望我说得够清楚。再次感谢您的帮助。我仍然无法使其正常工作。在验证部分,它检查空白字段,我删除了这些字段,因为在选择“新建”和“租赁”或“购买”时,无论发生什么,它都会继续抛出错误。所以我只留下了一个验证,那就是经销商的名字。无论如何,当我选择使用并提交表单时,我会得到所有值,但当我提交带有新选择的表单时,然后是PUCHASED或LEASED,我只会得到前几个值,如经销商名称、购买类型和报价,其他所有值都为空。有人能解释一下原因和他们所关心的其他问题吗see@ObsidianAge没有不同的操作URL表单会转到php页面,在那里进行验证等。但是,我使用了isset($_POST['parameter'])实际上是多个,因为有一些需要填写。无论如何,我现在遇到的问题是,当我点击submit(提交)按钮时,比如说,对于一种新的购买类型,当电子邮件发送给我时,一些字段是空的。还有一些未发送的字段是每种采购类型都需要填写的字段。这意味着它也不是一个隐藏字段,因此应该显示,但它不是。如果您提交的字段在页面上没有“存在”,它们将在插入中显示为空白。您还可以使用
isset($\u POST['parameter'])
检查是否存在
$\u POST
。你不能“正常”提交表格吗?恐怕我很难看出这个问题。您是否有不同形式的
action=
URL?@obsidiane感谢您的见解。我甚至没有想到这一点,我的意思是我想知道它们是否会作为空白发送。我想现在唯一的问题是我不希望所有的空白字段都通过电子邮件发送。好的,假设这是一辆二手车,它总共只有12个输入字段,但是,假设新购买的字段有18个,并且一些输入字段是不同的。如何删除要通过电子邮件发送的非相关字段。电子邮件发送部分等,我知道如何做了。我是否可以使用某种类型的catch,以便它只发送所用下拉选择的输入字段。@ObsidManager基本上我想我说的是,当我确保字段不为空,并将$_POST['value']存储到一个变量中时,我是否会像上面在newformprocess.php文件中所说的那样,以正常方式执行此操作。不管表单在什么时候被提交,比如说其中一个存储到变量的$\u POST,如果它在$\u POST['value']中没有任何内容,那么它将是空的。对不起,希望我说得够清楚。再次感谢您的帮助。我仍然无法使其正常工作。在验证部分,它检查空白字段,因为
<?php 

        if(isset($_POST["submit"]))
        {

            // Checking For Blank Fields....
            if($_POST['offerType']==""|| $_POST['typeOfPurchase'] =="" ||$_POST['marketing']==""||$_POST['input_1']==""||$_POST['input_2']==""||$_POST['input_3']==""||$_POST['input_4']==""||$_POST['input_5']==""||
            $_POST['input_6']==""||$_POST['input_7']==""||$_POST['input_9']==""||$_POST['input_10']==""||$_POST['input_11']==""||$_POST['input_12']==""||$_POST['input_13']==""||$_POST['input_14']=="")
                { 
?>
                    <script>
                        alert("Please complete the text marked with an *.");
                    </script>
<?php
                }

        else{

            $Offer = $_POST['offerType'];
            $typeOfpurchase = $_POST['typeOfPurchase'];
            $Marketing = $_POST['marketing'];
            $Field1 = $_POST['input_1'];
            $Field2 = $_POST['input_2'];
            $Field3 = $_POST['input_3'];
            $Field4 = $_POST['input_4'];
            $Field5 = $_POST['input_5'];
            $Field6 = $_POST['input_6'];
            $Field7 = $_POST['input_7'];
            $Field8 = $_POST['input_8'];
            $Field9 = $_POST['input_9'];
            $Field10 = $_POST['input_10'];
            $Field11 = $_POST['input_11'];
            $Field12 = $_POST['input_12'];
            $Field13 = $_POST['input_13'];
            $Field14 = $_POST['input_14'];
            $Field15 = $_POST['input_15'];
            $Field16 = $_POST['input_16'];
            $Field17 = $_POST['input_17'];
            $message = $_POST['input_18'];
            $message = wordwrap($message, 70);
            $form_content = 
            "What Type of Offer: $Offer
            If your purhcase was new what was your type of purchase: $typeOfpurchase
            Which Marketing Medium: $Marketing
            Dealership Name: $Field1
            Offer Start Date: $Field2
            Offer End Date: $Field3
            Year of Vehicle: $Field4
            Make of Vehicle: $Field5
            Model of Vehicle: $Field6
            Trim of Vehicle: $Field7
            Model # Vehicle: $Field8 
            Stock # of Vehicle: $Field9
            MSRP of Vehicle: $Field10
            Selling Price of Vehicle: $Field11
            Down Payment on Vehicle: $Field12
            XXX/ Month on Vehicle: $Field13
            Last 6 of VIN on Vehicle: $Field14
            Rebate on Vehicle: $Field15
            APR on Vehicle: $Field16 
            Residual Payment on Vehicle: $Field17 
            Other Notes (Rebate Info, Special Details etc): $message";

            $email_subject = "Online Offer Submission Form";

            $arrEmail = array('Jonathan <myemail@myemail.com?>');


                foreach($arrEmail as $key => $email_to)
                mail($email_to, $email_subject, $form_content);

                header('location: http://www.mydealerworld.com/thank-you-for-contacting-dealer-world/');
    }
        }
$.ajax({
'url':'newformprocess.php',
'type':'post',
'data':{'submit':true,'another_key':your_assigned_variable},
success:function(){
//when successfully sent
},
error:function(){
//if an ajax error occures, do something
}
});