Forum Moderators: coopster

Message Too Old, No Replies

How to validate radio boxes?

         

ksponline

2:48 am on Aug 5, 2003 (gmt 0)

10+ Year Member



Hi,

How are radio boxes validated with php?

Part of my form gives a choice of 4 credit cards, and one has to be selected, but I don't have a clue as to how to validate it. Actually I've checked one by default to avoid validating, but I'm wondering how to validate if one wasn't checked initially.

<tr>
<td class="right">Payment Method:</td>
<td><input name="Payment" type="radio" value="Visa" checked>
Visa
<input type="radio" name="Payment" value="MasterCard">
MasterCard
<input type="radio" name="Payment" value="Discover">
Discover
<input type="radio" name="Payment" value="Amex">
American Express</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="Card_Method" type="radio" id="Card_Method" value="Card_On_File" checked>
Please use my credit card on file<br>
<input name="Card_Method" type="radio" id="Card_Method" value="Card_Will_Call">
I will call with my credit card information</td>

I'm validating the text fields like so:
if ($Name == "")
{
$name_err = "<font color=red>Please enter your name.</font><br>";
$send = "no";
}
etc.

and with a little help with an earlier post, that's working fine.

Any help would again be appreciated...

Thanks!

vincevincevince

7:22 am on Aug 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



validate :

if (!$_REQUEST['payment']) die("Card type not selected.");

use data (suggestion) :


switch ($_REQUEST['payment'])
{
case "Visa" : echo "The card was a visa card"; break;

case "MasterCard" : echo "The card was a MasterCard"; break;

default : die("Unrecognised card / hacking attempt");
}

ksponline

11:44 pm on Aug 5, 2003 (gmt 0)

10+ Year Member



Thanks very much! I appreciate your taking the time to show me.