dongshendie8849 2016-06-25 21:04
浏览 81
已采纳

在提交时发送“按钮”-ID

I have an PHP page, which contains a form with some different input fields, e. g. day, month, year etc.. The form method is POST, only one non-editable field (The user ID) is sent via GET. Of course, there is a "Submit"-Button, which triggers the form Action (PHP Script on Server).
The form tags contain a table with empty cells too. Now comes my question:

If the user clicks into one of the table cells, the form should be submitted, but additional to the regular form data the ID of the table cell should be transmitted too (If via POST or GET doesn't matter to me). How can I do that?

//Edit 2:

...
<form method="post" action="<?= DOMAIN?>/.../addUserTimetable.php?uid=<?= $user->getUserID() ?>">
  <select id="day" name="day">
    ...
  </select>
  ...
  <input name="yearend" id="yearend" ...>
  <button type="submit">...</button>
  <table class="bordered">
    <tr>
      <th>Std.</th>
      <th>Montag</th>
      <th>Dienstag</th>
      <th>Mittwoch</th>
      <th>Donnerstag</th>
      <th>Freitag</th>
    </tr>
    <?php 
      for($i=1; $i<13;$i++) {
        echo "<tr>";
        echo "<th>".$i. "</th>";
        for($j=1;$j<6;$j++) {
          echo "<td id='h".$i. "d".$j. "' onclick='???'></td>";
        }
        echo "</tr>";
      }
    ?>
  </table>
</form>
...

The server sided procession is fine, but I haven't got any ideas - even after two hours google - how I could transmit the cell id additionally.

  • 写回答

1条回答 默认 最新

  • doremifasodo0008008 2016-06-25 21:26
    关注

    That shouldn't be to hard. Have a look at the following example:

    <form>
        <input type="text" name="something">
    
        <table>
           <tr>
              <td><input type="submit" name="cel1">
           </tr>
           <tr>
              <td><input type="submit" name="cel2">
           </tr>
           <tr>
              <td><input type="submit" name="cel13">
           </tr>
        </table>
    
        <input type="submit" value="save"> 
    </form>
    

    By giving the submit buttons in the table cells a name attribute, that name will also be present as a key on the $_REQUEST. Go ahead and var_dump the $_REQUEST and you'll see you can find out in the backend which button got pushed by checking which key exists.

    Note that POST / GET is completely irrelevant here, both will work just the same. And obviously you could apply some css to those buttons to make them transparent and lay them on top of the table cells, so they don't look like buttons, but just "capture" the user's click.

    One last side note, are you sure you want to send the userID as a GET parameter? That would be very easy for someone with bad intentions to manipulate. Consider not sending the ID at all, but keeping it in the session on the server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?