|
Posted by Norman Peelman on 10/27/07 13:10
Gustaf wrote:
> I've been working on a membership form for a while, and find it very
> tedious to get an acceptable level of form validation. A web search for
> solutions revealed some home-brewed solutions, such as these:
>
> http://simonwillison.net/2003/Jun/17/theHolyGrail/
> http://samuelsjoberg.com/archive/2004/11/form-validation-on-client-and-server
>
>
> Quoting from the first link, this is my idea of what form validation is
> like from the user's perspective:
>
> 1. The form is displayed; you fill it in.
> 2. You submit the form to the server.
> 3. If you missed something out or provided invalid input, the form is
> redisplayed pre-filled with the valid data you already entered.
> 4. The redisplayed form tells you what you got wrong. It also flags
> the fields that were incorrect.
> 5. Loop until you fill the form in correctly.
>
> In my membership form, I've found this to be complicated, error-prone
> and tedious if coded by hand in PHP. Plus, I find that very little of
> the code that comes out of it can be reused. There must be a better way...
>
What exactly are you having problems with? Or do you need a better
explanation (walk through) of items 1-5?
I do this:
1) I create my form and load it as a template
a) this form template has placeholders for various default values,
errors, etc.
b) these are used for hints and css styling
2) Upon submission I validate each field by regex
a) if ommissions or errors then repopulate the form, activate
errors, hints, etc. and give it back
3) When form is completed... do my stuff.
a) form is complete when all required fields are present and validated.
b) I keep a count of the required fields that pass validation and
consider the form ready when that count is met.
c) this lets you validate non-required fields if entered.
> I'm all for coding by hand, but in this case, the most productive
> environment I can imagine would be a WYSIWYG IDE environment, where you
> draw the form and pick most properties from drop-down lists. The IDE
> would then generate all the code for you, and offer to FTP it to the
> right location. I believe this is what Microsoft wanted to accomplish
> with Web Forms in ASP.NET. The big drawback there (correct me if I'm
> wrong) is that ASP.NET forms only work on IIS servers and IE clients. Is
> there anything like ASP.NET Web forms, but less MS-centric, and using
> PHP code? If not, what's the next best solution?
>
> Many thanks in advance.
>
> Gustaf
Norm
Navigation:
[Reply to this message]
|