Re: Validate Radio Buttons? [message #182372 is a reply to message #182371] |
Wed, 31 July 2013 21:37 |
Denis McMahon
Messages: 634 Registered: September 2010
Karma:
|
Senior Member |
|
|
On Wed, 31 Jul 2013 15:07:17 -0400, Jerry Stuckle wrote:
> On 7/31/2013 2:20 PM, Twayne wrote:
>> Should one Validate Radio Buttons for an online website contact form?
> Good practice means you ALWAYS validate ALL information from the user.
> You may have a radio button on your form - but there is no guarantee the
> request comes on from your form.
As a follow up to Jerry, radio buttons and select lists are probably the
easiest elements to validate in the server side code because, by
definition, you expect them to be one of a discrete set of values, and if
they're not a member of that set of values, then someone is playing silly
buggers.
You could use in_array to check that the value received is in an array of
expected values, and then use the value directly; or you could switch on
the value received, with a case for each of the expected values. In both
cases, you can detect and respond as you feel appropriate for unexpected
values.
--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
|
|
|