Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当同一表单中有多个复选框时,如何通过POST使用PHP脚本访问复选框_Php_Javascript_Jquery_Html_Forms - Fatal编程技术网

当同一表单中有多个复选框时,如何通过POST使用PHP脚本访问复选框

当同一表单中有多个复选框时,如何通过POST使用PHP脚本访问复选框,php,javascript,jquery,html,forms,Php,Javascript,Jquery,Html,Forms,我有一个用于编辑通知的表单,如下所示: <form action='edit.php' method = 'post'> <b> Username</b>:<br/> <input type='text' name ='username' value ="<?=$username?>" /><br/> <input type = "checkbox" id="r_notif" name="r_notif"

我有一个用于编辑通知的表单,如下所示:

<form action='edit.php' method = 'post'>
<b> Username</b>:<br/> <input type='text' name ='username' value ="<?=$username?>" /><br/>

<input type = "checkbox" id="r_notif" name="r_notif" checked="yes" /> Response Notifications<br/>
<input type = "checkbox" id="c_notif" name="c_notif" checked="yes" /> Comment Notifications<br/>
<input type ='submit' value = 'SEND' /> 
</form>
在edit.php中,我想为名为resp_notif的输入将$r_notif的值设置为1 if checked=yes。类似地,我想将$c_notif的值设置为1,如果输入c_notif的checked=yes。在每种情况下,我都将它们设置为零

问题是我只知道如何访问$\u POST['name\u of_field'],而不知道如何访问选中的值……如何在PHP或其他语言中实现这一点

谢谢

试试看

if(isset($_POST['name_of_field']))

以及检查/不检查复选框的不同变体。你应该能够回答你自己的问题逐字逐句,这是非常鼓励stackoverflow!很快。

在标记中添加值字段是一个好主意,这样您就可以确定文章的内容,并且不会因浏览器而异

<input type = "checkbox" id="r_notif" name="r_notif" checked="yes" value="yes" />
<input type = "checkbox" id="c_notif" name="r_notif" checked="yes" value="yes" />
<input type = "checkbox" id="r_notif" name="r_notif" checked="yes" value="yes" />
<input type = "checkbox" id="c_notif" name="r_notif" checked="yes" value="yes" />
if($_POST['r_notif'] == 'yes') $r_notif = 1;
else $r_notif = 0;
if($_POST['c_notif'] == 'yes') $c_notif = 1;
else $c_notif = 0;