douya5331 2013-09-06 10:24
浏览 216

PHP如何获取按钮列表的值

I want a list of buttons in a form and on postback I'd like to interrogate the list to see what status the buttons are at (by background colour if you are interested.)

The following codes says that Buttonx is undefined

However using the text boxes it works fine.

In javascript I can get at the array of buttons - at least in my real program.

If this is not possible, and an explanation would be useful, does anyone have a workaround at how I can get at the buttons in my postback. (In the real code the buttons are dynamically created depending on an sql query list)

<?php      
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
      var_dump($_POST['Buttonx']);
  }
?>

<form name="RegisterStudents" action="" method="post">
  <button  type="submit" name="myButton">Submit</button>
  <!--
  <input type="text" name="Buttonx[]" id="B0" value="0" />
  <input type="text" name="Buttonx[]" id="B1" value="1" />
  <input type="text" name="Buttonx[]" id="B2" value="2" />
  <input type="text" name="Buttonx[]" id="B3" value="3" />
  --> 

  <button type="button" name="Buttonx[]" id="B0" >0</button>
  <button type="button" name="Buttonx[]" id="B1" >1</button>
  <button type="button" name="Buttonx[]" id="B2" >2</button>
  <button type="button" name="Buttonx[]" id="B3" >3</button>

</form>

Thanks Gordon

  • 写回答

3条回答 默认 最新

  • doutao8774 2013-09-06 10:28
    关注

    Using forms you cannot pass the form elements with type="button" to server their values are not passed to server instead you have to use any other type to send the information to server on client side you can access their values this is the default nature of html

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器