c_pattle Posted October 9, 2010 Share Posted October 9, 2010 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? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 9, 2010 Share Posted October 9, 2010 within each checkbox or radio tag [code=php:0] echo "<input type='checkbox' name='checked_value' value='$somevalue'"; if ($checked_value == $somevalue) { echo " checked='checked'"; } echo " />"; Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 9, 2010 Share Posted October 9, 2010 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"' : ""; ?>> Quote Link to comment Share on other sites More sharing options...
Oziam Posted October 9, 2010 Share Posted October 9, 2010 You have to use checked! e.g <input type=radio name=radio1 checked> and <input type=checkbox name=check1 checked> and if you want to show a select option as selected you use "selected" hope this helps! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.