具有相同名称的多个隐藏输入,始终检索最后一个输入 [英] Multiple hidden input with same name, always retrieve the last input
本文介绍了具有相同名称的多个隐藏输入,始终检索最后一个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
foreach ($graphEdge as $graphNode) {
echo
"<div class='form-check mb-3'>" .
"<input type='radio' name='fb_profile' class='form-check-input' value='".$graphNode['name']."'>" .
"<img class='mr-2' src='" . $graphNode['picture']['url'] . "'>" .
"<label class='form-check-label' for='fb_profile'>" .
$graphNode['name'] . '</label>' .
"</div>";
echo "<input type='hidden' name='fb_access_token' value='" . $graphNode['access_token'] . "'>";
echo "<input type='hidden' name='fb_id' value='" . $graphNode['id'] . "'>";
}
正如标题所示,我有3个名为"fb_id"的隐藏输入,当我在表单中进行POST时将始终检索最后的隐藏输入,而fb_access_token将始终正确进行POST.
As the title suggests, I have 3 hidden inputs named 'fb_id' that when I POST in a form will always retrieve the last hidden input yet fb_access_token will always POST correctly.
推荐答案
好.从对话中可以看到,您想获取值,该值取决于radio
.
您可以这样操作:
Ok. As I see from conversation, you want to get values, which depends on radio
.
You can do it this way:
foreach ($graphEdge as $graphNode) {
echo
"<div class='form-check mb-3'>" .
"<input type='radio' name='fb_profile' class='form-check-input' value='".$graphNode['name']."'>" .
"<img class='mr-2' src='" . $graphNode['picture']['url'] . "'>" .
"<label class='form-check-label' for='fb_profile'>" .
$graphNode['name'] . '</label>' .
"</div>";
echo "<input type='hidden' name='fb_access_token[".$graphNode['name']."]' value='" . $graphNode['access_token'] . "'>";
echo "<input type='hidden' name='fb_id[".$graphNode['name']."]' value='" . $graphNode['id'] . "'>";
}
然后您可以通过radio
值来获取选定的值,如下所示(假设您的表单发送POST请求):
And then you can get selected values by radio
value like this (let's suppose your form sends POST request):
$profile = $_POST['fb_profile'];
$accessToken = $_POST['fb_access_token'][$profile];
$id = $_POST['fb_id'][$profile];
这篇关于具有相同名称的多个隐藏输入,始终检索最后一个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文