0

So i have a form and i don't want to clear fields when form submitted.

I can do this for simple input types :

<input name="name" value="<?php echo $_POST['name']; ?>>

But for array checkboxes

<input type="checkbox"  name="ans[]" value="2" class="grp1" onclick="phaseCheck();">
<input type="checkbox"  name="ans[]" value="3" class="grp1" onclick="phaseCheck();">

How I can reload and check which checkboxes checked by the user?

Thanks!

1 Answer 1

1

Use in_array function

<input type="checkbox" <?php if(in_array(2,$_POST['ans'])) { echo "checked"; } ?> name="ans[]" value="2" class="grp1" onclick="phaseCheck();">
<input type="checkbox" <?php if(in_array(3,$_POST['ans'])) { echo "checked"; } ?>  name="ans[]" value="3" class="grp1" onclick="phaseCheck();">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.