persistent $_POST for radio buttons, checkboxes & selects
Posted: Fri Sep 10, 2010 2:47 pm
I'm trying a new way of handling forms. In the past I've done validation 1st on the client side (JavaScript), then server side (PHP). The PHP that handled the form was on an external page. If $errors = true, the handler would display a list of errors & present a 'go back' button.
In an effort to make the form friendlier for people who have JS disabled, I've moved the PHP form handling to the same page as the form. I've figured out how to retain typed-in data in a text field by using something like this:
So that if a user submits the form and errors are displayed via PHP, the user doesn't have to re-enter all the form data. But how do I retain checked="checked" or selected="selected" states for radio buttons, checkboxes, and select inputs? I tried this guy's method, but it didn't work.
Thanks,
--cz
In an effort to make the form friendlier for people who have JS disabled, I've moved the PHP form handling to the same page as the form. I've figured out how to retain typed-in data in a text field by using something like this:
Code: Select all
<input type="text" name="foo" id="foo" value="<?php if(isset($_POST['submit'])){echo htmlentities($_POST['foo']) ?><?php } ?>" />Thanks,
--cz