dougua9328 2014-12-03 10:57
浏览 35
已采纳

在php中发布unchecked值的方法

I am displaying list of texts with an submit button in each row called "edit".

I am using post method.

When the user want to edit more than one text they can check a checkbox and they can click on any "edit" button.And i know how handle the texts when the user checks the checkbox.

But if they want to edit only one texts then its not necessary to check checkbox.

How can i handle if the user does not check any of the check box.

For example user want to edit apartment he clicks on "edit" button which is in the same line. How can i get the text of this in post method. All these texts are dynamic i am getting from data base.row

<form method='post' action="edit.php">
<tr><td>
 <input type="checkbox" value="1" name="check_list[]">
 </td><td><input type='text' name="text[]" value="casa|house|home" /></td>
  <td><input type="submit" value="edit></td>
  </tr>
 < tr><td>
 <input type="checkbox" value="2" name="check_list[]">
 </td><td><input type='text' name="text[]" value="apartments" /></td>
  <td><input type="submit" value="edit></td>
  </tr>
  • 写回答

1条回答 默认 最新

  • dongliang1873 2014-12-03 11:01
    关注

    If you set the name of the Submit buttons, you'll get them in the $_POST array under that key. You can then filter the $_POST to find which button was pressed.

    --- in html ---

    <input type="submit" name="edit_1" value="edit>
    

    --- in action.php ---

    foreach( $_POST as $key => $value ) {       // run over list of posted fields
      if( strpos( $key, "edit_" ) === 0 ) {     // if it starts with edit_
        $valueOfPressedButton = substr( $key, 5 ); // strip away the edit_ so that only the number of the button remains 
      }
    }
    

    Keep in mind that is a rather strange way to handle input and will not be straight forward in code as a result.

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

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c