Jump to content


PHP radio-button validation ???

  • Please log in to reply
1 reply to this topic

#1 j4mes_bond25

  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 05 July 2006 - 04:30 PM

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

<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 ???

#2 toplay

  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 05 July 2006 - 04:42 PM

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>

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users