doucaishou0074 2018-04-01 13:42
浏览 27

PHP循环使用创建表单但单击哪一个?

Hey i am using a PHP loop to create a table where each row in the table is a form. This part is fine.

I am now stuck. When i press submit it does not matter which form i press the submit button for it just passes the values from the last form to my php script.

Is there a way to know which button has been clicked? each of the fields are unique as i am using a row counter.

echo'  <input type="hidden" name="buyerID'.$rowcounter.'" value="'.$buyerID.'">';

So if i knew which form was submitted i could use

$buyerID= $_POST['buyerID'.$formnumber];

to get the values that i want but i cannot work out what to do. I thought that by creating multiple forms it would submit the value of the form submitted but this does not seem to be the case.

This is my table code:

<table class="table mb-0">
   <thead>
 <tr>
   <th></th>
   <th>Name</th>
   <th>Address</th>
   <th>Post Code</th>
   <th>City</th>
     </tr>
    </thead>
   <tbody>
    <tr>  <td>
    <form action="companyRating.php" method="post" name="myForm1"> 
    <input type="submit" value="Select" name="formbutton1" id ="formbutton1" class="linkButton" />
<input type="hidden" name="buyerID" value="033f4480-cdeb-44d9-b23f-17fb017f1ab5">
<input type="hidden" name="buyerName" value="CORVINVIEW LIMITED">
<input type="hidden" name="invoiceValue" value="2000">
<input type="hidden" name="issueDate" value="2018-04-02">
<input type="hidden" name="regNumber" value="01737132">
<input type="hidden" name="buyerStreet" value="UNION WORKS">
<input type="hidden" name="buyerPostCode" value="E10 5DJ"> 
<input type="hidden" name="buyerCity" value="LONDON">
<input type="hidden" name="buyerCountry" value="GB">
</form>
</td>  
<td><div id="buyerName" title="CORVINVIEW LIMITED">CORVINVIEW LIMITED</div></td>  
<td><div id="buyerStreet1">UNION WORKS<div></td>  
<td>E10 5DJ</td>  
<td>LONDON</td></tr>
<tr>  <td>
<form action="companyRating.php" method="post" name="myForm2"> 
<input type="submit" value="Select" name="formbutton2" id ="formbutton2" class="linkButton" />
<input type="hidden" name="buyerID" value="21d123c8-06f9-4279-93ba-4d69307b9ea7">
<input type="hidden" name="buyerName" value="CORRIBVIEW SAFETY SERVICES LIMITED">
<input type="hidden" name="invoiceValue" value="2000">
<input type="hidden" name="issueDate" value="2018-04-02">
<input type="hidden" name="regNumber" value="0574526">
<input type="hidden" name="buyerStreet" value="CORRIBVIEW SLIEVEROE">
<input type="hidden" name="buyerPostCode" value="">
<input type="hidden" name="buyerCity" value="HEADFORD">
<input type="hidden" name="buyerCountry" value="GB">
</form>
</td>  
<td><div id="buyerName" title="CORRIBVIEW SAFETY SERVICES LIMITED">CORRIBVIEW SAFETY SERVICES LIMITED</div></td>  
<td><div id="buyerStreet1">CORRIBVIEW SLIEVEROE<div></td>  
<td></td>  
<td>HEADFORD</td>
   </tr>                  
</tbody>
</table>

It doesn't matter if i select the first form on the 2nd the values of the 2nd are always sent

  • 写回答

1条回答 默认 最新

  • dtf76989 2018-04-01 13:46
    关注

    You already said each row in the table is a form. Then the submit button within the row belongs to the form for said row.

    To figure out, which row this is, the name should remain constant for all forms:

    echo '<input type="hidden" name="buyerID" value="'.$buyerID.'">';
    

    So, to figure out which buyerID was used, simply fetch it from the post data:

    $buyerID = $_POST['buyerID'];
    
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)