在带有php的表单中保存复选框的值 [英] Save value of Checkboxes in a form with php

查看:141
本文介绍了在带有php的表单中保存复选框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助保存用户选择的复选框的值。



我有两个复选框的形式:

 < form action =process.phpmethod =POST> 
选项一:< input type =checkboxname =check1value =1/>
选项二:< input type =checkboxname =check2value =2/>
&br>

< input type =submitvalue =Submit/>
< / form>


<?php

if(isset($ _ POST ['check1'])){

//执行函数A


}

elseif(isset($ _ POST ['check2'])){


执行函数B

}

?>

现在如果用户勾选Option One并点击submit,复选框保持选中状态,php代码如果用户勾选选项二,执行另一个功能,并且复选框2保持选中状态,则执行某些功能。



请有人帮我整理。

谢谢!

解决方案

如果您希望在提交后保持检查: p>

 选项一:< input type =checkboxname =check1value =1<?php if ($ _POST ['check1']))echo'checked =checked'; > /> 
选项二:< input type =checkboxname =check2value =2<?php if(isset($ _ POST ['check2']))echo'checked =checked ; > />


I need some help saving the value of the checkbox that user has selected.

I have two checkboxes in the form:

<form action="process.php" method="POST">
Option One: <input type="checkbox" name="check1" value="1"/>
Option Two: <input type="checkbox" name="check2" value="2"/>
<br>

<input type="submit" value="Submit" />
</form>


<?php

if(isset($_POST['check1'])){

//execute function A


}

elseif(isset($_POST['check2'])){


//execute function B

}

?>

Now if the user ticks "Option One" and clicks submit, the checkbox remains checked and the php code executes some function otherwise if the user ticks "Option two" another function is executed and the checkbox 2 remains checked.

Please someone help me sort this out.

Thankyou!

解决方案

If you want to keep them checked after submitting:

Option One: <input type="checkbox" name="check1" value="1" <?php if(isset($_POST['check1'])) echo 'checked="checked"'; ?> />
Option Two: <input type="checkbox" name="check2" value="2" <?php if(isset($_POST['check2'])) echo 'checked="checked"'; ?> />

这篇关于在带有php的表单中保存复选框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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