0

我创建了一个表单,如果他们“有东西”,用户将在其中选择是。我在具有发布操作的表单中使用它,然后将值发送到 .php 文件。当我尝试使用它检查按钮时,if (isset($_POST['agentsele']))它不会回读。我里面有一些打印语句要测试,但它永远不会通过。我将输入字段从按钮变为复选框并尝试读取它 - 它有效。转回去之后就不行了。

这里是输入字段。

<input type="button"  value="Yes" name="agentsele" class="agentsele"/>

检查方法。

if (isset($_POST['agentsele'])) {

                $emailaction = 1;//email agent and set status to - enrolled - agent emailed
                echo "agent selected";
                exit;
            }

如果选择了按钮,我还有一些 JQuery 会使更多的输入框向下滑动。

感谢您的时间。

更新-------- 整个表格

<form name="theform" action="insert.php" method="post" >
                <div class="CheckBoxContainer">
            <input type="checkbox" value"On" name="only-thisform"/>
            <?php 
            $setError=$_GET['seterror'];

            if ($setError == 1){

                echo "<div class='errorMsg'> *Required</div>";
            }
             ?>
            <br>
            <br>

            <input type="checkbox"  value="On" name="approval" id="approval"/>
             <?php 
             $setError=$_GET['seterror'];
             if ($setError == 1){

                echo "<div class='errorMsg'> *Required</div>";
             }

             ?>
            </div><!------------------------------------END   .CheckBoxContainer ------------------------------------------->
            <br>
            <br>


<script type="text/javascript"
     src="http://code.jquery.com/jquery-latest.min.js">
</script>   
<!-- javascript on client-side -->


<div class="DropDownSelector">
<?php

$dropdown = "<select name='CompanyNames' id='CompanyNames' >";

$dropdown .= "\r\n<option  id ='' name ='' value='' class=''  ></option>";

$dropdown .= "\r\n<option  id ='other' name ='other' value='other' class='other'  >other</option>";

while($row =$FNresult->fetch()) {

  $dropdown .= "\r\n<option  id ='firstname' name ='first' value='{$row['CompanyNames']}'>{$row['CompanyNames']}</option>";
}

$dropdown .= "\r\n</select>";

echo $dropdown;
?>
    <div class="DropdownDiscription">Please select your insurance company.  Select other if you do not see it listed. </div>
</div> <!------------------------------------------END .DropDownSelector -------------------------------------------------------->
<script type="text/javascript">  

var dropdown = $('#CompanyNames');
//var test = $('#firstname');
//document.write(dropdown.val());

dropdown.bind('change', function(){

     if(dropdown.val() == "other"){
        $(".otherbox").slideDown(1000,function(){
           // $(this).css("border", "2px red inset")            
        });  
         $(".InputDiscriptionother").slideDown(1000,function(){
           // $(this).css("border", "2px red inset")            
        });          
    }else{
          $(".otherbox").slideUp(1000); 
           $(".InputDiscriptionother").slideUp(1000);   
    }

    $.post('backgroundScript.php', 
        { 
            'CompanyNames': dropdown.val()

        },
        function(response) {
            $('#compname').val(response.Companyname);
            //$('#phone').val(response.phone);
            //$('#policynum').val(response.policynum);
            //$('#nameofPolicyholder').val(response.policyholder);
            //$('#mailing').val(response.mailing);
            // Repeat for all of your form fields
        },
        'json'
    );

});
</script>
<br>


<!--<input type="text" class="otherbox" />
<input type="text" class="otherbox" />

<input type="text" class="otherbox"/>-->

<div class="FormBody">

    <div class="InputContainer">
<span class="InputDiscriptionother">Insurance Company Name: </span><div class="InputInner"> <input type="text" name="compname" id="compname" class="otherbox" ></div><!----- END .InputInner ---------->

<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>

</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
    <div class="InputContainer">
<span class="InputDiscription">Insurance Phone number: </span><div class="InputInner"><input type="text"  name="phone" id="phone" ></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>

</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<div class="InputContainer">
     <div class="agensele"> Do you have an agent? <input type="button"  value="Yes" name="agentsele" class="agentsele"/></div><!----- END .InputInner ---------->
     <?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required only if selected</span>";
    }
else
    //echo "<span>*</span>"; 
?>
     <div class="noagensele"> Do you have an agent? <input type="button"  value="No" name="noagentsele" class="noagentsele"/> </div><!----- END .InputInner ---------->
</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<div class="InputContainer">
<span class="agent">Agent Name: </span><div class="InputInner"> <input type="text" name="agentname"  class="agentinput" ></div><!----- END .InputInner ---------->



</div><!---------------------------------END .InputContaienr ----------------------------------->

<div class="InputContainer">
<span class="agent">Agent Phone Number: </span><div class="InputInner"> <input type="text" name="agentphone"  class="agentinput" ></div><!----- END .InputInner ---------->



</div><!---------------------------------END .InputContaienr ----------------------------------->
<div class="InputContainer">
<span class="agent">Agent's Email: </span><div class="InputInner"> <input type="text" name="agentemail"  class="agentinput" ></div><!----- END .InputInner ---------->



</div><!---------------------------------END .InputContaienr ----------------------------------->
<div class="InputContainer">
<span class="agent">Confirm Agent's Email: </span><div class="InputInner"> <input type="text" name="agentemailone"  class="agentinput" ></div><!----- END .InputInner ---------->



</div><!---------------------------------END .InputContaienr ----------------------------------->
<script>
$(".agentsele").click(function () {
    $(this).css({ borderStyle:"inset", cursor:"wait" });
    //dropdown.bind('change', function(){   
    $(".agentinput").slideDown(1000,function(){
    });
    $(".agent").slideDown(1000,function(){
    });
    //$(".agentsele").css("visibility", "hidden");
    //$(".agensele").css("visibility", "hidden");
    $(".noagentsele").css("visibility", "visible");
    $(".noagensele").css("visibility", "visible");
});
$(".noagentsele").click(function () {
    $(this).css({ borderStyle:"inset", cursor:"wait" });
    //dropdown.bind('change', function(){   
    $(".agentinput").slideUp(1000,function(){
    });
    $(".agent").slideUp(1000,function(){
    });
    $(".agentsele").css("visibility", "visible");
    $(".agensele").css("visibility", "visible");
    $(".noagentsele").css("visibility", "hidden");
    $(".noagensele").css("visibility", "hidden");
});

</script>

<br>
    <div class="InputContainer">
    <span class="InputDiscription">Name of the Policyholder: </span><div class="InputInner"><input type="text" name="nameofPolicyholder" id="nameofPolicyholder"></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>

</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<div class="InputContainer">
     <div class="InputInner"> Not the Policy Holder? <input type="checkbox"  value="On" name="notpolicyholder" class="notpolicyholder"/></div><!----- END .InputInner ---------->
</div><!---------------------------------END .InputContaienr ----------------------------------->

<br>
    <div class="InputContainer">
<span class="InputDiscription">Policy Number: </span><div class="InputInner"><input type="text" name ="policynum" id="policynum" ></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>


</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
    <div class="InputContainer">
<span class="InputDiscription">Policyholder mailing address: </span><div class="InputInner"><input type="text" name="mailing" id="mailing"></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>

</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
    <div class="InputContainer">
<span class="InputDiscription">City: </span><div class="InputInner"><input type="text" name="city" id="city"></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>


</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
    <div class="InputContainer">
    <!------------------------------------------STATE SELECTION CODE ------------------------------------------->
<?php
    function state_select ($name,$full_state,$selected = '') {

  $state_list = array("AL|Alabama","AK|Alaska","AZ|Arizona", "AR|Arkansas", "CA|California", "CO|Colorado", "CT|Connecticut", "DE|Delaware", "DC|Washington D.C.", "FL|Florida", "GA|Georgia", "HI|Hawaii", "ID|Idaho", "IL|Illinois", "IN|Indiana", "IA|Iowa", "KS|Kansas", "KY|Kentucky", "LA|Louisiana", "ME|Maine", "MD|Maryland", "MA|Massachusetts", "MI|Michigan", "MN|Minnesota", "MS|Mississippi", "MO|Missouri", "MT|Montana", "NE|Nebraska", "NV|Nevada", "NH|New Hampshire", "NJ|New Jersey", "NM|New Mexico", "NY|New York", "NC|North Carolina", "ND|North Dakota", "OH|Ohio", "OK|Oklahoma", "OR|Oregon", "PA|Pennsylvania", "RI|Rhode Island", "SC|South Carolina", "SD|South Dakota", "TN|Tennessee", "TX|Texas", "UT|Utah", "VT|Vermont", "VA|Virginia", "WA|Washington", "WV|West Virginia", "WI|Wisconsin", "WY|Wyoming");

  ?>
  <select name=<?=$name;?> id="state" onChange="submitform()"><?
    foreach ($state_list as $s) {
        $values = explode("|",$s);
        ?><option value="<?=$values[0];?>" <?
                if($selected == $values[0]) { ?>SELECTED<? }
                ?>>

                <?  if($full_state) { ?><?=$values[1];?><? } else { ?><?=$values[0];?><? } ?></option><?
    }
  ?></select><?
}
?>

<span class="InputDiscription">State: </span><div class="InputInner">
<?=state_select('state',false,'AL'); ?>
<input type="hidden" id="hiddenfield" name="hiddenfield" value="">
 </div><!----- END .InputInner ---------->

<?php

 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 

?>

</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<div class="InputContainer">
<span class="InputDiscription">Zipcode: </span><div class="InputInner"><input type="text" name="zipcode" id="zipcode"></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>


</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<br>
<div class="InputContainer">
<span class="InputDiscription">Year Of Vehicle: </span><div class="InputInner"><input type="text" name="YearOfVehicle" id="YearOfVehicle"></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>


</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<div class="InputContainer">
<span class="InputDiscription">Make Of Vehicle: </span><div class="InputInner"><input type="text" name="MakeOfVehicle" id="MakeOfVehicle"></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>


</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<div class="InputContainer">
<span class="InputDiscription">Model Of Vehicle: </span><div class="InputInner"><input type="text" name="ModelOfVehicle" id="ModelOfVehicle"></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>


</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<div class="InputContainer">
<span class="InputDiscription">Vehicle Identification Number: </span><div class="InputInner"><input type="text" name="Vehicleid" id="Vehicleid"></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>


</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<div class="InputContainer">
<span class="InputDiscription">Policy Effective Date: </span><div class="InputInner"><input type="text" name="Policyeffdate" id="Policyeffdate"></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>


</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<div class="InputContainer">
<span class="InputDiscription">Policy Expiration Date: </span><div class="InputInner"><input type="text" name="Policyexpdate" id="Policyexpdate"></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>


</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<br>
<h2>Employee Information</h2>

<div class="InputContainer">
<span class="InputDiscription">Employee Name: </span><div class="InputInner"><input type="text" name="EmployeeName" id="EmployeeName"></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>


</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<br>
<div class="InputContainer">
<span class="InputDiscription">Employee Company Name: </span><div class="InputInner"><input type="text" name="EmployeeCompanyName" id="EmployeeCompanyName"></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>


</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<div class="InputContainer">
<span class="InputDiscription">Agency/Franchise Number (or unique indicator): </span><div class="InputInner"><input type="text" name="Agency/FranchiseNumber" id="Agency/FranchiseNumber"></div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>


</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<div class="InputContainer">
<span class="InputDiscription">Todays Date: </span><div class="InputInner"><input type="text" name="TodaysDate" id="TodaysDate" value="
<?php

$today = date("n-j-Y"); 
echo $today;
?>">
</div><!----- END .InputInner ---------->
<?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "<span class='errorMsg'>*Required</span>";
    }
else
    //echo "<span>*</span>"; 
?>


</div><!---------------------------------END .InputContaienr ----------------------------------->
<br>
<div class="CheckBoxContainer">
            <input type="checkbox" value"On" name="correct"/>The above printed name serves to identify the employee and shows intent of the employee that the above auto insurance information given is accurate.  
            <?php 
            $setError=$_GET['seterror'];

            if ($setError == 1){

                echo "<div class='errorMsg'> *Required</div>";
            }
             ?>
            <br>
            <br>

            <input type="checkbox"  value="On" name="agree" id="agree"/>The employee identified above confirms this document has been read, reviewed and understood and subsequently authorizes it as such. 
             <?php 
             $setError=$_GET['seterror'];
             if ($setError == 1){

                echo "<div class='errorMsg'> *Required</div>";
             }

             ?>
             <br>
             <br>
             <input type="checkbox"  value="On" name="understood" id="understood"/>The employee understands that if inaccurate information is discovered on the above auto insurance information table, on the employee's auto policy itself or if the auto insurance policy is cancelled for any reason, the employer will be notified. 
             <?php 
             $setError=$_GET['seterror'];
             if ($setError == 1){

                echo "<div class='errorMsg'> *Required</div>";
             }

             ?>
            </div><!------------------------------------END   .CheckBoxContainer ------------------------------------------->
            <br>
<?php 
 $setError=$_GET['seterror']; 
if($setError == 1){
echo "<script type='text/javascript'>alert('Please check to make sure all required fields are filled out!');</script>";
}
?>


<input type="Submit" name="Submit" >

</div><!-------------------------------------------END .FormBody ------------------------------------------------------->
</form>

更新 - - - - - - - - - -

当我更改类型以提交它时,它工作但我不希望它直接将我发送到它插入数据的函数。如何阻止它提交。

4

4 回答 4

4

按钮值未随表单提交一起发送

于 2012-08-21T19:38:50.263 回答
1

按钮不能包含表单数据,请改用提交

于 2012-08-21T19:39:14.493 回答
0

您可以在表单中隐藏“输入”类型,并使用 jQuery 向按钮添加事件。

于 2012-08-21T19:54:33.660 回答
0

首先,我们可以尝试标准化您的控制。

<input type="submit" name="Submit" value="Submit" /> 

http://www.w3.org/TR/html401/interact/forms.html#h-17.4


也许对按钮的一些澄清也会有所帮助。

http://www.w3.org/TR/html401/interact/forms.html#h-17.5


当我更改类型以提交时,它可以工作,但我不希望它直接将我发送到它插入数据的功能。我如何阻止它提交。

我的 JavaScript 有点生疏,但我相信您可以使用该onsubmit属性来做某事,或者您可以使用标签的onload=""属性<form>或更常见的<body>标签来注册一些功能。找一本好的 JavaScript 书籍,里面有关于表单的部分。

http://www.amazon.com/JavaScript-Definitive-Guide-Activate-Guides/dp/0596805527/ref=sr_1_1?s=books&ie=UTF8&qid=1401399613&sr=1-1&keywords=javascript+the+definitive+guide

于 2014-05-29T21:41:48.110 回答