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
https://forums.phpfreaks.com/topic/215516-retaining-checkbox-values/
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"' : ""; ?>>

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.