Check box set with PHP form post?

How do I check?

I tried 1, incl. And yes. This does not work. Putting the triggered "checked" one works alone, but then how do I check with PHP after the message form flag is checked?

<input type="checkbox" class="inputcheckbox" id="newmsg" name=chk[newmsg2] value="1" /> 
+4
source share
3 answers

The checkbox will be successful only if it is set.

Failed controls are not passed as data.

Therefore, you can find out if the checkbox is checked by seeing if its value has been transmitted.

for instance

 if ($_POST['chk']['newmsg2'] == 1) { 
+4
source

Here is the code;

 <form action="test.php" method="POST"> <input type="checkbox" class="inputcheckbox" id="newmsg" name=chk[newmsg2] value="1" /> <input type="submit"> </form> <?php $check = $_POST['chk']['newmsg2']; echo "***$check****" ?> 

If checked, $ check will show 1.

0
source
 <input type="checkbox" class="inputcheckbox" id="newmsg" name=chk[newmsg2] value="1" <?php if ($_POST['chk']['newmsg2']): ?>checked="checked"<?php endif; ?> /> 
0
source

Source: https://habr.com/ru/post/1309165/


All Articles