Jump to content

PHP radio-button validation ???


j4mes_bond25

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:

http://members.lycos.co.uk/darsh25/AllInclusiveWebDesign/contact.php

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>

<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
</td>
</tr>
[/code]

Wonder why's this happening ??? Can anyone help ???
Link to comment
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>

Link to comment
Share on other sites

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.