isset($ _ POST ['读取按钮']) - 无法正常工作

时间:2012-08-21 19:36:54

标签: php

我创建了一个表单,如果用户“有某些东西”,用户将选择“是”。我在一个具有post动作的表单中使用它,然后将值发送到.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 个答案:

答案 0 :(得分:4)

未使用表单提交

发送按钮值

答案 1 :(得分:1)

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

答案 2 :(得分:0)

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

答案 3 :(得分: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