Jump to content

[SOLVED] Using if (isset($_POST['ap_nmF'])) on radio buttons


Recommended Posts

How do I do this: [code]<input size="20" name="ap_nmF" value="<?php if (isset($_POST['ap_nmF'])) echo $_POST['ap_nmF']; ?>" />[/code]
on a "radio" button, when all the radio buttons use the same name?
[code]
<input type="radio" class="radio" name="ap_bnk1" value="Apple">
<input type="radio" class="radio" name="ap_bnk1" value="Grape">
<input type="radio" class="radio" name="ap_bnk1" value="Orange">
<input type="radio" class="radio" name="ap_bnk1" value="Pear">
[/code]

Any help would be apprechiated?
I have a form, that if required fields arent inserted and error page displays telling the user to complete the required fields. Problem is that when the user clicks back to correct the problems all the data is lost. I figured out that on a text box you can use
[code]<input size="20" name="ap_nmF" value="<?php if (isset($_POST['ap_nmF'])) echo $_POST['ap_nmF']; ?>" />[/code] and it will hold  the information, but how do you do the same type thing on a radio button if all the radio buttons use the same name, just have different values?

The page I'm working on is here. [url=http://www.carcityofdanbury.com/apply.php?applicant=single]http://www.carcityofdanbury.com/apply.php?applicant=single[/url]

(Hopefully my explanation helps...)
[quote author=bibby link=topic=124360.msg515103#msg515103 date=1169947793]
Do you ppl code?

He's trying to get the value of his radio choice into a text field.

Bookatay,  what you have should work if POST['ap_nmF'] is set.  Is It ?
create an ELSE and see what happens..

[/quote]
I like how you acted like we were morons yet you were wrong.

DBookatay rather than have an error page, just have the errors appear on the same page as the form. Keep all the previously submitted info in variables and set them as the inputs values so the info is not lost. There is no need for an isset, as the input will just be blank if it isn't set. If they didn't put in a value then the box will be empty.

If you mean you want the same radio button selected as the one they previously selected then make a variable for each one, and if that was the previously selected one set it as "CHECKED".

e.g.

[code]if ($_POST['ap_bnk'] == "Apple") {
$radio1 = "CHECKED";
}[/code]

and put the relevant variable in the end of each radio button.

E.g.

[code]echo <<<HERE
<input type="radio" class="radio" name="ap_bnk1" value="Apple" $radio1>
<input type="radio" class="radio" name="ap_bnk1" value="Grape" $radio2>
<input type="radio" class="radio" name="ap_bnk1" value="Orange" $radio3>
<input type="radio" class="radio" name="ap_bnk1" value="Pear" $radio4>
HERE;
[/code]
[quote author=Tandem link=topic=124360.msg515119#msg515119 date=1169948819]
I like how you acted like we were morons yet you were wrong.
[/quote]
My thoughts exactly...

Thank you Tandem, that is what I was trying to acheve...
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.