Jump to content


This topic is now archived and is closed to further replies.


PHP radio-button validation ???

Recommended Posts

I've a contact form, on my nearly finished website, allowing viewers to send the data, which I've validated with different validation rule depending on the data required for a field itself.

Website itself can be seen on:


Problem is with last 2 fields i.e. "Reply Required" AND "How would you like to be contacted?"

If user press the submit button, I want the "filled" fields remain same, hence, making them NOT to re-type what they's already done. I wish to do the same for these 2 options as well, hence whichever radio button they'd chosen, after pressing submit, if they mis-filled any fields (for example, "e-mail"), then I want the option chosen in 2 radio buttons staying same i.e. whatever they'd chosen

Problem is, after pressing "Submit" the radio button options for these 2, ALWAYS goes to the "second option" regardless of the option chosen ??? This makes them RE-chose the radio button option.

Related code

[code=php:0]<tr id="contactTable">
<td id="contactTable">Reply Required:</td>
<td id="contactTable"><input type="radio" name="reply" value="Yes" checked="checked"/>Yes
<input type="radio" name="reply" value="No" <?php if ($reply="No") echo "checked='checked'"; ?>/>No</td>

<tr id="contactTable">
<td id="contactTable">How would you like to be contacted <span class="italic">(if required)</span>?<br/><br/></td>
<td id="contactTable"><input type="radio" name="contact" value="Email" checked="checked"/>E-mail
<input type="radio" name="contact" value="Telephone" <?php if ($contact="Telephone") echo "checked='checked'"; ?>/>Telephone

Wonder why's this happening ??? Can anyone help ???

Share this post

Link to post
Share on other sites

I'll do one to get the idea, and you can fix the other. You are using one equal sign instead of two (==), plus you need to do the same thing on the 'Yes' option.

// Assume you have something like this set already (use $_GET or $_POST):
$reply = isSet($_REQUEST['reply']) ? $_REQUEST['reply'] : 'Yes'; // Set default

<td id="contactTable"><input type="radio" name="reply" value="Yes" <?php if ($reply == "Yes") echo 'checked="checked"'; ?>/>Yes
<input type="radio" name="reply" value="No" <?php if ($reply == "No") echo 'checked="checked"'; ?>/>No</td>

Share this post

Link to post
Share on other sites


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.