On 1/19/06, Richard Lynch <ceo@xxxxxxxxx> wrote: > > 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. These are example questions and values. The actual values are numerical since it is a ranking so 1 means 1 (or first) in the results. > 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 :-) Neither of these are options my client wants -- no plug-ins even Flash and I need to allow that JS may not be on. > 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?... Here's the error message: *Warning*: array_count_values(): Can only count STRING and INTEGER values! in */home/www/test/test.php* on line *206* 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. I'm not including all my code here...I'm trying to keep it simple so I can get at the main issue. As you noted below I'm trying to validate in two directions or as you say below, I'm trying to cover both...the radio buttons take care of it one way (the row) and I'm trying to figure out how to do it for the column as well. 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. They do have the option to change their answers once they submit and get a message saying one of the required questions is not filled in. I also give them what answers they have supplied previously. I do this for the radio buttons as well. > 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 > > >