Please someone tell me how I can show to the user what checkboxes he selected, after he clicks the submit button.
| SitePoint Sponsor |
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? :P
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.
HTML Code:<input type="checkbox" name="chk1" value="PHP" /> PHP <input type="checkbox" name="chk2" value="Javascript" /> JavaScriptPHP Code:if(isset($_POST['chk1']) && !empty($_POST['chk1'])){
echo $_POST['chk1'];
}
Oh you mean you will be in the same page/form after submitting the form? If so do something like this:
But be sure you submitted the form in the same page and page should remain containing the posted data.PHP Code:<input type="checkbox" name="chk1" value="PHP"<?php echo if(isset($_POST['chk1']) && !empty($_POST['chk1'])) ? ' checked="checked"' : '';?> /> PHP





No need for !empty with a checkbox, it will default to "on"
Thank you rajug and hash. Now works.
Bookmarks