多个复选框在提交后不检查 [英] Multiple Checkbox not checking after submitting

查看:130
本文介绍了多个复选框在提交后不检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$color="";<br>
$sel4="";<br>
$suc="";<br>
if(isset($_POST['save']))   <br>
{<br>
$e="0";<br>
if(isset($_POST['color']))<br>
{<br>
    $color=$_POST['color'];<br>
}<br>
else<br>
{<br>
    $sel4="<--Check Any Color";<br>
    $e="1";<br>
}<br>
if($e==0)<br>
{<br>
$suc="Success";<br>
}<br>
}<br>
?><br><br><br>
~~body~~<br>
~~form method="POST"~~<br>
~~table~~<br>
~~tr~~<br>
~~td~~<br>
color<br>
~~/td~~<br>
~~td~~<br>
~~input type="checkbox" name="color" value="blue" ~~? if($color=='blue'){ echo "checked";  }?>  /><br>Blue<br>
~~input type="checkbox" name="color" value="red" ~~? if($color=='red'){ echo "checked"; }?>  /><br>Red<br>
~~input type="checkbox" name="color" value="green" ~~? if($color=='green'){ echo "checked";  }?>  />Green<br>
~~input type="checkbox" name="color" value="yellow" ~~? if($color=='yellow'){ echo "checked";   }?>  />Yellow<br>
~~/td~~<br>
~~td~~?=$sel4;?~~<br>
~~/tr~~<br>
~~tr~~<br>
~~td colspan="3"~~<br>
~~input type="submit" name="save"~~<br>
~~/td~~<br>
~~?=$suc?~~<br>
~~/tr~~<br>
~~/table~~<br>
~~/form~~<br>
~~/body~~<br>

<br><br><br>

注意:此处未使用html标记<所以我使用~~而不是<>


主题:这个程序工作正常..但是当我提交更多一个复选框,被检查的项目不在 CHECKED
在提交表单后,只选中一个项目。< br>< br>

NOTE: html tag<> not used here. So i used "~~" instead of "<>".

Subject: This program working perfectly.. But when i submitting with MORE THAN ONE check box., the checked items is not in CHECKED.
Only one item is checked., after submitting the form.<br><br>

例如:

当我选中蓝色和红色颜色时,它在提交后仅选中红色所以我需要解决这个错误。帮助我!

For Example:
When i check 'Blue' and 'Red' color., it Checked only 'Red' color after Submitting. So i need the solution for this error. Help Me!.

推荐答案

您应该将复选框声明为数组

you should declare your checkbox as arrays

<input type='checkbox' name='color_list[]' value="red">
<input type='checkbox' name='color_list[]' value="blue">
<input type='checkbox' name='color_list[]' value="green">

,以便在获得 $ _ POST ['color_list'] 你将选择颜色数组。你可以这样做:

so that after you get it $_POST['color_list'] you'll have the array of colors selected. you could do something like this:

$colors_selected = $_POST['color_list'];

然后只需使用 implode()。我希望这有助于。

then just use some function like implode(). I hope this helps.

这篇关于多个复选框在提交后不检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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