|
Posted by "Richard Lynch" on 01/20/06 02:01
On Mon, January 16, 2006 9:16 pm, HiFi Tubes wrote:
> I'm kind of a newbie so speak sllllooooowly.
>
> I've got a problem with validating radio buttons that seems to be
> harder
> than I think to solve. I've got ten items set up like this:
>
> Green: <input type="Radio" name="color1" value="1" /> <input
> type="Radio"
> name="color1" value="2" /> <input type="Radio" name="color1" value="3"
> />
> and son on out to 10.
Doesn't answer your question, but you really should use:
name="color[1]" to keep your sanity when you process these in PHP...
Or, honestly, I'd use name="green" or name="color[green]" so I knew
green was green instead of having to memorize (or, in my case, FAIL to
memorize) that 1 means green.
> Then I've got Red: <input type="Radio" name="color2" value="1" /> and
> so on
> out to ten again.
>
> So I've got ten colors each with 10 radio buttons so that they can be
> ranked
> from 1 to 10. The problem? Well, obviously, the user can only pick
> one
> value in the row for each color. That part is simple. BUT I also
> need to
> make sure that they only rank one color with the value "1" and, of
> course,
> only one color can have "2" and so on. How do I validate this so that
> they
> get a warning before they submit that user has picked more one color
> with
> the same ranking?
If you want the warning before they submit, and if you accept the fact
that there is no inherent HTML widget to do that (there isn't) then
your options are all client-side, and have nothing to do with PHP at
all, really, so you're asking in the wrong place...
That said, I'll be polite (this time) and suggest some areas for
research.
#1. Javascript
You can use Javascript to check whatever fields/attributes you want.
Note that the user can turn off or bypass Javascript and submit
invalid info, so you STILL need to run the check again server-side to
be SURE you have valid data.
#2. Flash
You could maybe make a much nicer color-coded fancy interface in Flash.
I HATE flash personally, but depending on your user-base, it might be
appropriate...
I doubt it, but it might be :-)
> An additional complication: They don't have to answer or rank all the
> colors. All they really need to do is rank one color to copmplete the
> question.
>
> I created an array with the answers and then used array_count_values
> to find
> out the frequency but that chokes on color rankings that are left
> blank.
Chokes how?...
If they select nothing at all for one of your colors, then nothing
gets sent for that color to the web-server. That's just how HTTP/HTML
works.
So if you assumed that $color2 would have some value, and they clicked
on no radio button at all, it won't.
Note also that this is a pretty bad interface in that they could click
on, say, red #3 and then decide they didn't want to pick red at all,
and they are SCREWED -- You have given them no way to change their
mind and say "no input" to $color2 in the radio buttons, and once you
click any radio button, you are stuck with at least one of them
clicked.
> How do I assure that only one color is ranked at any one value?
>
> I hope my question makes sense. Any help will be appreciated.
--
Like Music?
http://l-i-e.com/artists.htm
Navigation:
[Reply to this message]
|