Jump to content

how to retain checkbox values


verdure

Recommended Posts

Hi

 

I have a registration form with form validations for some text fields.

 

the form also have some check boxes and radio buttons.

 

On submission of the form the validations are checked in formvalidation.php file.

and error messages are sent back to the registration page.

 

 

In this process i am unable to retain the values of checkbox or radio button submitted first.

 

Could somebody please direct as to how to retain values of checkbox/ radio buttons.

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/120513-how-to-retain-checkbox-values/
Share on other sites

one way that i sometimes do this is

 


<form action="#" method="POST">
<input <?php if ($_POST['dog'] == 'checked') { echo 'checked ';} ?> type="checkbox" name="dog" value="checked" />
<input <?php if ($_POST['cat'] == 'checked') { echo 'checked ';} ?> type="checkbox" name="cat" value="checked" />
<input <?php if ($_POST['frog'] == 'checked') { echo 'checked ';} ?> type="checkbox" name="frog" value="checked" />
<input type="submit" value="submit">
</form>

 

this form just links to the same page, but basically if one of the inputs is checked the value of $_POST['dog'] will be whatever is in the value ("checked in that case) in the html tag (with the name "dog"). So i just check for that and if its true, echo checked into the form.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.