Checkbox selected after submit

Please someone tell me how I can show to the user what checkboxes he selected, after he clicks the submit button.

Can’t he see that before he clicks submit? :stuck_out_tongue:

Maybe you have some code?

Simply with $_POST variable. The selected checkboxes along with their respective values (that you put in the HTML) will be available for you in the $_POST super global array.

<input type="checkbox" name="chk1" value="PHP" /> PHP
<input type="checkbox" name="chk2" value="Javascript" /> JavaScript

if(isset($_POST['chk1']) && !empty($_POST['chk1'])){
    echo $_POST['chk1'];

Thank you, but how can I put the selected sign on what was selected, instead of printing out that $_POST[‘chk1’] ?

Oh you mean you will be in the same page/form after submitting the form? If so do something like this:

<input type="checkbox" name="chk1" value="PHP"<?php echo if(isset($_POST['chk1']) && !empty($_POST['chk1'])) ? ' checked="checked"' : '';?> /> PHP

But be sure you submitted the form in the same page and page should remain containing the posted data.

No need for !empty with a checkbox, it will default to “on”

Well it was just a kind of typo hash :). I had just typed it for all post variables. Indeed that is not needed in case of checkbox.

Thank you rajug and hash. Now works.