Forum Moderators: coopster

Message Too Old, No Replies

Radio Buttons

After validating form, want to show selected radio button

         

kieftrav

10:04 pm on Sep 24, 2006 (gmt 0)

10+ Year Member



After submitting a form, I have the form validated and then reshow the form prepopulated with POST data, but I can't get the radio buttons to work so that they show the previously selected one after submitting.

How can I get that to work?

P.S. I haven't tried checkboxes, but I'm assuming that they may be similar in their problems. Any solution for that too?

Thanks,
Travis

eelixduppy

10:21 pm on Sep 24, 2006 (gmt 0)



If the value of the _POST var matches the radio button you have to add the CHECKED attribute, like this:

<input type="radio" name="category" value="bugs" [b]checked[/b]>

Good luck!

kieftrav

1:45 am on Sep 25, 2006 (gmt 0)

10+ Year Member



Hey eelixduppy, thanks for the tip but it didn't work...

Here is an example of the output. I made it into an array so that the output isn't just "on"...

[radiotime] => Array
(
[0] => parttime
)

Any other ideas?

Travis

eelixduppy

3:46 pm on Sep 25, 2006 (gmt 0)



I'm not quite sure what problems you are having with this. Posting code may enable us to help you more. From the looks of everything, it should look something like this:

<input type="radio" name="radiotime" value="parttime" <?php echo ($_POST['radiotime'] == "parttime")? "checked":"";?> >

This utilizes the ternary operator [us3.php.net].

I hope this helps!

kieftrav

1:05 am on Sep 26, 2006 (gmt 0)

10+ Year Member



Worked like a charm eelixduppy. I should have thought of that... Oh well. I appreciate the help.

Travis

eelixduppy

1:13 am on Sep 26, 2006 (gmt 0)



You're Welcome.

>>I should have thought of that

Don't be too hard on yourself, we are all here to learn! The important thing is now you understand how it works, and you'll be able to use these skills in the future.