【问题标题】:Identify $_POST type in php识别 php 中的 $_POST 类型
【发布时间】:2015-11-25 16:06:06
【问题描述】:

嗨,我的表单中有很多输入,其中一些是单选按钮,另一些是文本和文本框。我通过

获得所有这些值
foreach ($_POST as $name => $val)
{
 //for example if post type==radio
 //there is some insertion codes to db in here $name,$val...

}

但如果 post 值是单选按钮,我想使用该插入。我该怎么做?

我的表单看起来像

<form method="post" action="<?=$_SERVER['REQUEST_URI']?>">
.
.
.
//a lot of table,tr,td,input,etc. in this part
.
.
.

<td style="border-style:solid; border-width:2px 1px 1px 2px"><input type="radio" class="metalYayaKorkuluk_Deformasyon" name="metalYayaKorkuluk_Deformasyon" style="width:100%; margin:0px; display:table-caption" value="1" /></td>
<td style="border-style:solid; border-width:2px 1px 1px 1px"><input type="radio" class="metalYayaKorkuluk_Deformasyon" name="metalYayaKorkuluk_Deformasyon" style="width:100%; margin:0px; display:table-caption" value="2" /></td>
<td style="border-style:solid; border-width:2px 1px 1px 1px"><input type="radio" class="metalYayaKorkuluk_Deformasyon" name="metalYayaKorkuluk_Deformasyon" style="width:100%; margin:0px; display:table-caption" value="3" /></td>
<td style="border-style:solid; border-width:2px 2px 1px 1px"><input type="radio" class="metalYayaKorkuluk_Deformasyon" name="metalYayaKorkuluk_Deformasyon" style="width:100%; margin:0px; display:table-caption" value="4" /></td> 

<td style="border-style:solid; border-width:1px 1px 2px 2px"><input type="radio" class="plastikKaplama4" name="plastikKaplama4" style="width:100%; margin:0px; display:table-caption" value="1" <?php echo ($plastikKaplama4=='1')?'checked':'' ?>/></td>
<td style="border-style:solid; border-width:1px 1px 2px 1px"><input type="radio" class="plastikKaplama4" name="plastikKaplama4" style="width:100%; margin:0px; display:table-caption" value="2" <?php echo ($plastikKaplama4=='2')?'checked':'' ?>/></td>
<td style="border-style:solid; border-width:1px 1px 2px 1px"><input type="radio" class="plastikKaplama4" name="plastikKaplama4" style="width:100%; margin:0px; display:table-caption" value="3" <?php echo ($plastikKaplama4=='3')?'checked':'' ?>/></td>
<td style="border-style:solid; border-width:1px 2px 2px 1px"><input type="radio" class="plastikKaplama4" name="plastikKaplama4" style="width:100%; margin:0px; display:table-caption" value="4" <?php echo ($plastikKaplama4=='4')?'checked':'' ?>/></td>


<input id='elm2' type="submit" name="save2" value="Submit" />

</form>

总结一下,我试图使用 foreach 获取所选单选按钮的所有名称及其值,但我不想获取其他输入,例如 text 和 textarea。

【问题讨论】:

标签: php post foreach


【解决方案1】:

您应该使用 Javascript 为每个输入发布隐藏的输入

<input type="hidden" name="radio" value="input1,input2" />

然后使用php

$radios = explode(',',$_POST['radio']);
foreach($radios as $value) {
    $radio_value = $_POST[$value];
    // Do you want
}

【讨论】:

  • expload 你来得太快了。主要错字。
猜你喜欢
  • 2016-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-28
  • 2017-04-29
  • 1970-01-01
相关资源
最近更新 更多