具有可变数量输入的$ _POST? [英] $_POST with variable number of inputs?

查看:94
本文介绍了具有可变数量输入的$ _POST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置一个读取$ _POST数据的系统,该数据来自用户决定的输入数量的表单?我可以使用诸如$ _POST [1]之类的索引吗? (例如,创建/移除页面,提交更改并处理用户决定需要的页面数量)

您的表单创建您的输入变量,名称以方括号结尾:

 < input name =lines []type =文本><峰; br> 
< input name =lines []type =text>< br>
< input name =lines []type =text>< br>

您可以根据需要添加任意数量,或者在JavaScript中快速创建它们。



提交表单时,数据将显示为$ _POST中的一个数组:

  echo $ _POST ['lines'] [0]; 
echo $ _POST ['lines'] [1];
echo $ _POST ['lines'] [2];


How can I set up a system that reads $_POST data that comes from a form with a user-decided number of inputs? Can I use an index such as $_POST[1] or something similar? (e.g. create/remove pages, submit changes and process an input for as many pages as the user decides they want)

解决方案

In your form create your input variables with names ending in square brackets:

<input name="lines[]" type="text"><br>
<input name="lines[]" type="text"><br>
<input name="lines[]" type="text"><br>

You can add as many as you need, or creat them on the fly in javascript.

When the form is submitted the data will appear as an array in $_POST:

echo $_POST['lines'][0];
echo $_POST['lines'][1];
echo $_POST['lines'][2];

这篇关于具有可变数量输入的$ _POST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆