2016-06-25 21:04
浏览 80


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">
  <input name="yearend" id="yearend" ...>
  <button type="submit">...</button>
  <table class="bordered">
      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>";

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.

图片转代码服务由CSDN问答提供 功能建议

我有一个PHP页面,其中包含一个带有一些不同输入字段的表单,例如: G。 日期,月份,年份等。表单方法是POST,只有一个不可编辑的字段(用户ID)通过GET发送。 当然,还有一个“提交”-Button,它触发表单Action(PHP) 服务器上的脚本)。
表单标签也包含一个带空单元格的表。 现在我的问题出现了:

如果用户点击其中一个表格单元格,则应提交表单,但除常规表单数据外,还应传输表格单元格的ID (如果通过POST或GET对我来说无关紧要)。 我该怎么做?


  ... \  n&lt; form method =“post”action =“&lt;?= DOMAIN?&gt; /.../ addUserTimetable.php?uid =&lt;?= $ user-&gt; getUserID()?&gt;”&gt; 
  &lt; select id =“day”name =“day”&gt; 
&lt; / select&gt; 
&lt; input name =“yearend”id =“yearend”...  &gt; 
&lt; button type =“submit”&gt; ...&lt; / button&gt; 
&lt; table class =“bordered”&gt; 
&lt; tr&gt; 
&lt; th&gt; Std。&lt;  / th&gt; 
&lt; th&gt; Montag&lt; / th&gt; 
&lt; th&gt; Dienstag&lt; / th&gt; 
&lt; th&gt; Mittwoch&lt; / th&gt; 
&lt; th&gt; Donnerstag&lt; / th&gt; 
&lt;  ;&gt; Freitag&lt; / th&gt; 
&lt; / tr&gt; 
 for($ i = 1; $ i&lt; 13; $ i ++){
 echo“&lt; tr&gt;”; \  n echo“&lt; th&gt;”。$ i。  “&lt; / th&gt;”; 
 for($ j = 1; $ j&lt; 6; $ j ++){
 echo“&lt; td id ='h”。$ i。  “d”。附加$ J。  “'onclick ='???'&gt;&lt; / td&gt;”; 
 echo“&lt; / tr&gt;”; 
&lt; / table&gt; 
&lt;  / form>

服务器支持游行很好,但我没有任何想法 - 即使在谷歌两个小时后 - 我怎么能 另外传输cell id。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • doremifasodo0008008 2016-06-25 21:26

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

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

    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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题