Jump to content

retaining checkbox values


c_pattle

Recommended Posts

I have a form and on each input I set the value as the post variable of it's self.  I do this so that if the user submit the form and it has errors they haven't lost the data they have inputted.  For example

 

<input name="input1" type="text" value="<?php echo($_POST['input1']); ?>" />

 

This works fine for text field and textarea's but how do I retain the value of radio boxes and checkboxes?

Link to comment
Share on other sites

Since checkboxes only show up in the $_POST array if they're actually checked, you can just check with isset.

 

<input type="checkbox" name="checkbox_name" value="true"<?php echo isset($_POST['checkbox_name']) ? ' checked="checked"' : ""; ?>>

Link to comment
Share on other sites

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.