Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.