$ _POST值以外的另一个属性 [英] $_POST another attribute than value
问题描述
是否可以通过$ _POST获得除名为value的属性以外的其他属性的值
Is it possible to get some other attribute's value than attribute named value with $_POST
example: <option value="FusRo" name="Dah"></option>
通常,当我使用$ _POST ['Dah']时,PHP会获取FusRo(值).
Normally when i use $_POST['Dah'] The php grabs FusRo (the value).
但是我想获取另一个属性的值,而不是名为value的属性.我希望你能理解.
But I want to grab another attribute's value than attribute named value. I hope you understand.
如果我不能使用$ _POST来获取其他值,那我可以使用其他命令吗?
If I cant use $_POST to grab some other value, is it some other comand i can use?
另一个例子: 如果我使用
Another example: If i use
<option value="FusRo" name="Dah"></option>
我可以用$ _POST代替"Fusro"来获得"Dah"吗?
Can I get the "Dah" with $_POST instead of "Fusro" ?
推荐答案
您可以将其他值放在隐藏字段中
You can put your other value in a hidden field:
<input type="hidden" name="DahHidden" value="somethingelse" />
然后使用以下方法从$_POST
获取它:
Then get it from $_POST
with:
$_POST['DahHidden']
如果必须根据<select>
中的内容动态更改此值,那么您将需要JavaScript.
If this value has to dynamically change based on what's in the <select>
, then you'll need JavaScript.
如果您想从$_POST
中获取键(即表单字段中的name
属性),则可以像这样遍历$_POST
:
If you want to grab the keys from $_POST
(i.e. the name
attributes from your form fields), you can iterate over $_POST
like this:
foreach( $_POST as $key => $value)
echo $key . ' => ' . $value; // Will print Dah => value (eventually)
请注意,遍历$_POST
可能会产生比仅一个表单元素更多的输出(除非'Dah'
是您在表单中提交的唯一内容.
Note that iterating over $_POST
will likely produce more output than just that one form element (unless 'Dah'
is the only thing you submitted in your form.
这篇关于$ _POST值以外的另一个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!