PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
edawson003
Forum Contributor
Posts: 133 Joined: Thu Aug 20, 2009 6:34 am
Location: Los Angeles, CA - USA
Post
by edawson003 » Wed Oct 14, 2009 12:18 am
How can code a radio button such that it retains it's value (checked) after a unsuccessful form post?
Here's how setup a a text field to retain value. I figure for radios, it should be too far off.
Code: Select all
<input class=clp type="text" name="exname" maxlength="50" size="40" value="<?php echo isset($exname) ? $exname : ''; ?>" />
Code: Select all
<input type="radio" name="extype" value="1">
<input type="radio" name="extype" value="2">
<input type="radio" name="extype" value="3">
Last edited by
edawson003 on Wed Oct 14, 2009 12:58 am, edited 1 time in total.
Mirge
Forum Contributor
Posts: 298 Joined: Thu Sep 03, 2009 11:39 pm
Post
by Mirge » Wed Oct 14, 2009 12:58 am
edawson003 wrote: How code a radio button such that it retains it's value (checked) after a unsuccessful form post?
Code: Select all
<input class=clp type="text" name="exname" maxlength="50" size="40" value="<?php echo isset($exname) ? $exname : ''; ?>" />
Code: Select all
<input type="radio" name="extype" value="1">
<input type="radio" name="extype" value="2">
<input type="radio" name="extype" value="3">
Well, one way would be to put an if() statement in each of the input radio's... for example (assuming form's method is POST):
Code: Select all
<input type="radio" name="extype" value="1"<?php if($_POST['extype'] == '1') { print "checked "; } ?>>
<input type="radio" name="extype" value="2"<?php if($_POST['extype'] == '2') { print "checked "; } ?>>
<input type="radio" name="extype" value="3"<?php if($_POST['extype'] == '3') { print "checked "; } ?>>
If you're using method="GET" instead, replace $_POST with $_GET.
edawson003
Forum Contributor
Posts: 133 Joined: Thu Aug 20, 2009 6:34 am
Location: Los Angeles, CA - USA
Post
by edawson003 » Wed Oct 14, 2009 1:29 am
works perfect! Thanks!
Mirge
Forum Contributor
Posts: 298 Joined: Thu Sep 03, 2009 11:39 pm
Post
by Mirge » Wed Oct 14, 2009 1:35 am
Not a problem.