同一PHP页面上的不同提交按钮

时间:2017-02-25 08:51:23

标签: php form-submit

我想询问一种在同一页面上使用多个提交按钮的方法 以下是流程:首先,用户从选择列表中进行选择,然后单击“有效”,然后将显示带有其他操作的数组

first senario

second senario

问题是只有第一个提交按钮处于活动状态,而第二个提交按钮不起作用

3 个答案:

答案 0 :(得分:0)

一种表格,只能提交一份。因此,如果您想要两个提交,请创建两个表单。

答案 1 :(得分:0)

 //here is the first code for the select list


<header class="panel-heading ">
                                <form action="index2.php" method="post" name="a">          <!-- first form  for the select list-->
                                    <fieldset> 
                                       Veuillez selectionnez un chantier : &nbsp;&nbsp;&nbsp;
                                     <select name="chantier" class=" dropdown-toggle"> 
                                            <option value="NULL">-- Selectionner --</option> 
                                            <?php 

                                    include"config.php";
                                     $str = $_SESSION['username'] ; 

                                    $query = " SELECT dbo.CH_PROTUSER.CH_Designation, dbo.CH_PROTUSER.CH_Num, 
                                    dbo.CH_ACCES.U_Login FROM dbo.CH_PROTUSER INNER JOIN dbo.CH_ACCES ON
                                    dbo.CH_PROTUSER.CH_Num = dbo.CH_ACCES.U_CHNUM Where dbo.CH_ACCES.U_Login= '$str' ";
                                    $result = sqlsrv_query($conn, $query);
                                    while( $rs = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC) ){
                                    ?>
                                    <option value="<?php echo $rs['CH_Num'];   "<option id='". $rs['CH_Num'] ."'>"?>" ><?php echo $rs['CH_Designation'] ?></option> <?php }
                                    $s=($_POST['chantier']);
                                    echo $s;
                                     ?>
                                </select>

                                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <input type="submit"  value="Valider"  class="btn btn-success btn-xs " i class="fa fa-check"></i>

                                    </fieldset> 
                                </form>
                            </header>

//这是第二个表单的第二个代码,它位于数组

           echo' <div class="row">
                <div class="col-sm-12">
                    <section class="panel">
                        <header class="panel-heading ">
                            Resultats
                        </header>
                        <table class="table responsive-data-table data-table">
                        <thead>
                                <tr>
                                    <th><center>CodeMDP</center></th>
                                    <th><center>Matricule</center></th>
                                    <th><center>Prenom</center></th>
                                    <th><center>Nom</center></th>
                                    <th><center>H.Norm</center></th>
                                    <th><center>H.DIV</center></th>
                                    <th><center>H.Supp</center></th>
                                    <th><center>Dimanche</center></th>
                                    <th><center>Ferier</center></th>
                                    <th><center> Modfier</center> </th>
                                    <th><center> Suprrimer</center> </th>
                                </tr>
                                </thead>
                                <tbody>';

                                while( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC) ){

                                    $xss =$row['P_MATRICULE'];

                                        echo "<tr><td>" .'<center>' . $row['P_CODECHT'] .'</center>'. "</td>
                                        <td>" .'<center>'. $row['P_MATRICULE'] .'</center>'. "</td>
                                        <td>" .'<center>'. $row['P_PRENOM'] .'</center>'. "</td>
                                        <td>"  .'<center>'. $row['P_NOM'] .'</center>'. "</td>
                                        <td>" .'<center>'. $row['P_HNORM'] .'</center>'. "</td> 
                                        <td>" .'<center>'. $row['P_HEURDIV'] .'</center>'. "</td>
                                        <td>" .'<center>'. $row['P_HEURSUP'] .'</center>'. "</td>
                                        <td>" .'<center>'. $row['P_HDIMANCH'] .'</center>'. "</td>
                                        <td>" .'<center>'. $row['P_HFERIER'] .'</center>'. "</td>
                                        <td>  <form action='' method='post' name='b'> " ."<center><button data-toggle='modal' Type='submit' name='xyz'  
                                        value='$xss' class=' btn btn-info' href='#myModal' ><i class='fa  fa-pencil' ></i></center> ". "</form></td>
                                        <td>" ."<center><button data-toggle='button' class=' btn btn-danger' name='xyz'  ><i class='fa fa-trash-o' ></i></button></center> ". "</td>
                                            </tr>"; 
                                        }   
                                         if(isset($_POST['xyz'])) { 
                                             echo"aa";
                                        $sss="$xss";
                                        $query2 = " SELECT P_HNORM,P_HEURDIV,P_HDIMANCH,P_HFERIER,P_HEURSUP
                                        FROM [C_POINTAGESEMPLOYE] WHERE P_MATRICULE = '$sss'  AND (SELECT CONVERT(VARCHAR(8), P_DATETX, 12) 
                                         AS [MM-DD-YY])   = (SELECT CONVERT(VARCHAR(8), GETDATE(), 12) AS [MM-DD-YY])";
                                          $result2 = sqlsrv_query($conn, $query2);
                                          while( $row2 = sqlsrv_fetch_array( $result2, SQLSRV_FETCH_ASSOC) )
                                        {
                                        $hn =($row2['P_HNORM']);
                                        $hd =($row2['P_HEURDIV']);
                                        $hs =($row2['P_HEURSUP']);
                                        $hdim =($row2['P_HDIMANCH']);
                                        $hf =($row2['P_HFERIER']);
                                        }
                                         }

                                    echo'
                            </tbody>
                        </table>


                    </section>

                </div>
                </div>
            <div class="row">
                <div class="col-md-12">
                     <section class="panel">
                        <header class="panel-heading ">                        
                            <p align="right">                      
                            <button type="button" class="btn btn-success "><i class="fa fa-check"></i>&nbsp;&nbsp; Confirmer </button>
                            </p>

                        </header>
                    </section>
                </div>
            </div>
            </div>' ;

答案 2 :(得分:0)

您可以通过单击第一个按钮来使用Ajax GET请求,并使用提交按钮附加第二个POST请求的元素。但是如果你想使用两个提交,你必须有两个表单,或者只有这两个表单是相同的。 并且完全错误从HTML生成SQL查询!!! 编辑

<强> 例如

  $('#selectbox1').change(function() { var data = ""; $.ajax({ 
    type:"GET", 
    url : "controller mapping", 
    data : "selectbox1_selectedvalue="+$(this).val(), 
    async: false,
     success : function(response) { 
    data = response; 
    return response; 
    }, 
    error: function() { 
    alert('Error occured');
     } 
    }); 
    var string = data.message.split(","); 
    var array = string.filter(function(e){
return e;
});
  $.each(array, function(index, value) {
    //here it's your form with inputs.
    $('#form').append("<input name="inputName" value="value"/>");
     }); 
    $('#form').show()
    });
  

这是选择更改