Best solution to tedious form validation?

Best solution to tedious form validation?

am 26.10.2007 18:47:42 von Gustaf Liljegren

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...

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

Re: Best solution to tedious form validation?

am 26.10.2007 18:52:31 von Jeff Gaines

On 26/10/2007 in message Gustaf
wrote:

>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.

Yes please, you write it I'll buy it :-)

--
Jeff Gaines Damerham Hampshire UK
By the time you can make ends meet they move the ends

Re: Best solution to tedious form validation?

am 26.10.2007 18:59:40 von Bucky Kaufman

"Jeff Gaines" wrote in message
news:xn0fcwvbj6tq8n006@news.individual.net...
> On 26/10/2007 in message Gustaf
> wrote:
>
>>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.
>
> Yes please, you write it I'll buy it :-)

It's called Visual Studio.net and it's availabe most anywhere for about five
hundred to a thousand bucks.
ASP.net has a whole facility for writing form-validation code, server and
client side.
It's wildly complex, but it works.

Re: Best solution to tedious form validation?

am 26.10.2007 19:25:59 von Jeff Gaines

On 26/10/2007 in message <02pUi.17225$JD.6758@newssvr21.news.prodigy.net>
Sanders Kaufman wrote:

>"Jeff Gaines" wrote in message
>news:xn0fcwvbj6tq8n006@news.individual.net...
>>On 26/10/2007 in message Gustaf
>>wrote:
>>
>>>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.
>>
>>Yes please, you write it I'll buy it :-)
>
>It's called Visual Studio.net and it's availabe most anywhere for about
>five hundred to a thousand bucks.
>ASP.net has a whole facility for writing form-validation code, server and
>client side.
>It's wildly complex, but it works.

I am an MSDN subscriber and have found nothing in VS 2005 that could be
called a decent visual IDE for HTML, and of course there is no mention of
php. In fact Kompozer is a better WYSIWYG IDE than VS :-(

I would love to be proved wrong, but I can't even specify the location of
web components in VS without coding it by hand.

--
Jeff Gaines Damerham Hampshire UK
I can please only one person per day. Today is not your day.
Tomorrow, isn't looking good either.

Re: Best solution to tedious form validation?

am 26.10.2007 20:07:09 von Bucky Kaufman

"Jeff Gaines" wrote in message
news:xn0fcww8t80r8j007@news.individual.net...
> Sanders Kaufman wrote:

>>It's called Visual Studio.net and it's availabe most anywhere for about
>>five hundred to a thousand bucks.
>>ASP.net has a whole facility for writing form-validation code, server and
>>client side.
>>It's wildly complex, but it works.
>
> I am an MSDN subscriber and have found nothing in VS 2005 that could be
> called a decent visual IDE for HTML, and of course there is no mention of
> php. In fact Kompozer is a better WYSIWYG IDE than VS :-(
>
> I would love to be proved wrong, but I can't even specify the location of
> web components in VS without coding it by hand.

Sorry.
I never meant to imply that it was WYSIWIG or PHP.
It does, however, have the described way of doing validation scripts on HTML
forms.

Re: Best solution to tedious form validation?

am 26.10.2007 23:52:45 von Jeff Gaines

On 26/10/2007 in message
Sanders Kaufman wrote:

>I never meant to imply that it was WYSIWIG or PHP.

You got my hopes up for a while, I thought I had missed something :-)

--
Jeff Gaines Damerham Hampshire UK
"Why is it that when we talk to God we're said to be praying,
but when God talks to us we're schizophrenic?"

Re: Best solution to tedious form validation?

am 27.10.2007 01:25:14 von Larry Anderson

On Oct 26, 9:59 am, "Sanders Kaufman" wrote:
> "Jeff Gaines" wrote in message
>
> news:xn0fcwvbj6tq8n006@news.individual.net...
>
> > On 26/10/2007 in message Gustaf
> > wrote:
>
> >>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.
>
> > Yes please, you write it I'll buy it :-)
>
> It's called Visual Studio.net and it's availabe most anywhere for about five
> hundred to a thousand bucks.
> ASP.net has a whole facility for writing form-validation code, server and
> client side.
> It's wildly complex, but it works.

And if you don't use Windows or Internet Explorer all that nifty
Validation stuff just doesn't work and the V.S. web guys can't fix the
code so they tell you you must use I.E..

Re: Best solution to tedious form validation?

am 27.10.2007 04:45:53 von Jeff North

On Fri, 26 Oct 2007 18:47:42 +0200, in comp.lang.php 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...

Have you looked at Pear::QuickForms ?
http://pear.php.net/package/HTML_QuickForm2
http://www.midnighthax.com/smarty-guide.php

>| 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
-- ------------------------------------------------------------ -
jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
-- ------------------------------------------------------------ -

Re: Best solution to tedious form validation?

am 27.10.2007 09:19:55 von Bucky Kaufman

wrote in message
news:1193441114.060334.189090@57g2000hsv.googlegroups.com...
> On Oct 26, 9:59 am, "Sanders Kaufman" wrote:

>> It's called Visual Studio.net and it's availabe most anywhere for about
>> five
>> hundred to a thousand bucks.
>> ASP.net has a whole facility for writing form-validation code, server and
>> client side.
>> It's wildly complex, but it works.
>
> And if you don't use Windows or Internet Explorer all that nifty
> Validation stuff just doesn't work and the V.S. web guys can't fix the
> code so they tell you you must use I.E..

Yup. I got my MCSD back in 2000 - .NET was still new.
Once I got a good whiff of VS.NET 2002 and 2003, I became a LAMP guy.

Re: Best solution to tedious form validation?

am 27.10.2007 15:10:55 von Norman Peelman

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

Re: Best solution to tedious form validation?

am 29.10.2007 15:02:46 von otrWalter

First step: Client side validation

Second Step: Server side validation

Can't help you with the second (I'm working on it!)

But on the first... How about just added 2 JS INCLUDE calls to your
page and then adding a pair of custom HTML tags to each Form Object
you want to have validated...

id="first_name"
name="first_name"
type="alpha" <- new attribute
required="true" <- new attribute
value="">

Would that help?

Walter

Re: Best solution to tedious form validation?

am 29.10.2007 16:19:38 von Shelly

wrote in message
news:1193666566.938124.262280@22g2000hsm.googlegroups.com...
> First step: Client side validation
>
> Second Step: Server side validation
>
> Can't help you with the second (I'm working on it!)
>
> But on the first... How about just added 2 JS INCLUDE calls to your
> page and then adding a pair of custom HTML tags to each Form Object
> you want to have validated...
>
> > id="first_name"
> name="first_name"
> type="alpha" <- new attribute
> required="true" <- new attribute
> value="">
>
> Would that help?
>
> Walter

In your suggestion you have type="text" and type="alpha" in the same input
tag.

Shelly

Re: Best solution to tedious form validation?

am 29.10.2007 19:43:32 von otrWalter

> In your suggestion you have type="text" and type="alpha" in the same input
> tag.

Yes, sorry...


id="first_name"
name="first_name"
datatype="alpha" <- new attribute int|alpha|phone|
email|etc
required="true" <- new attribute true|false
value="">

Thx for the catch

Walter

Re: Best solution to tedious form validation?

am 29.10.2007 20:40:35 von luiheidsgoeroe

On Mon, 29 Oct 2007 19:43:32 +0100, otrWalter@gmail.com =

wrote:

>
>> In your suggestion you have type=3D"text" and type=3D"alpha" in the s=
ame =

>> input
>> tag.
>
> Yes, sorry...
>
>
> > id=3D"first_name"
> name=3D"first_name"
> datatype=3D"alpha" <- new attribute int|alpha|phone=
|
> email|etc
> required=3D"true" <- new attribute true|false
> value=3D"">
>
> Thx for the catch

Well, let's invent HTML attributes? Invalid HTML means all bets are off =
on =

how anything will be handled, and only by the grace of UA's kind enough =
to =

process broken tagsoup HTML will it do anything resembling to what you =

want. Don't rely on that, use a real attribute. A classname comes to min=
d.

ue=3D"">

It can more reliable be read using javascript, is valid, and is the plac=
e =

where you're supposed to put this kind of stuff.

http://www.w3.org/TR/html401/struct/global.html#adef-class
"The class attribute has several roles in HTML:
- As a style sheet selector (when an author wishes to assign style =

information to a set of elements).
- For general purpose processing by user agents."
-- =

Rik Wasmus

Re: Best solution to tedious form validation?

am 30.10.2007 16:32:13 von otrWalter

> Well, let's invent HTML attributes? ... use a real attribute. A classname comes to mind.
>
>
>
> It can more reliable be read using javascript, is valid, and is the place
> where you're supposed to put this kind of stuff.

Yes, I read that in the spec. I din't agree with it then, and still
don't.

My JS class was written 10 years ago, pre-dates everything about HTML
validation, CLASS, etc.

The beauty of HTML (and CSS) is its ability to ignore attributes that
it doesn't know about. That *is* in the specs, therefore I decided to
"invent HTML attributes". It made the most logical sense (at the
time). Designers (who knew HTML) found it easy to understand and code.
It was easy to implement, and it failed gracefully.

Now, I don't know about CLASSNAME being "more reliable be read using
Javascript" than "invented" attributes. Any attribute added to any
HTML Tag is accessible via JS otherwise my method would not work.

>From a human readable, non-programmer POV, which do you think is more
apparent ...

id="first_name"
name="first_name"
datatype="alpha"
required="true"
value="">

.... OR ...

id="first_name"
name="first_name"
class="foo alpha required"
value="">

If someone really didn't know about the new CSS "elements", they would
be confused about what they mean, especially if they couldn't find
those elements in the assigned CSS file. Yes, they would learn, after
their initial confusion, what they mean. But this is just nit-picking.

But, on the other hand, anyone reading the first example would know
something was a-miss about the tag, that these "invented" attributes
are not "real" so they must have to do with something else on the
client-side. Again, petty point.

Understand, just because someone is a web designer (and I know *many*
who fall into this category) doesn't mean they know how to code in JS
or PHP or Perl. They know enough HTML to get a page built and CSS to
make it look right. My library was designed for people like that: load
a few JS files, add some attributes which anyone can understand, and
you now have instant client-side validation. No fuss, no muss, light
weight and clean.

Besides, 100% xHTML validation can ham-string any good design. 100%
xHMTL validation is a honorable goal and a lofty target, but it is not
realistic in the real world. It's the difference between theory and
practice, between science and engineering.

Also, why is blind faith adherence to validation such a good thing? If
the WC3 was all knowing, then they would have more attributes to
handle just this situation, (even mulit-level SELECT lists, which I
begged for 15 years ago!). But, instead, they gave us a spec that
allowed for a much more flexible format. Add an attribute if you like,
but we (WC3) will ignore it, use it for your own purposes, don't
expect us (WC3) to do anything with it.

So, yes, sir, I'm breaking validation. Yes, sir, I am among the
faithful, but not a blind follower. And Yes sir! I have a highly
flexible, readable, and *very* understandable (to anyone doing HTML)
client-side validation system. Which was my goal, my point, my target.

I can live with my web pages being 99% xHTML validated as long I can
get things done in a clean manner. And besides, to my (weird) logical
mind, adding elements to CLASS that have nothing to do with CSS is
"just not logical". But adding non-validatable (is that a word?)
attributes to a tag in order to "extend the language/features" does
make sense. Afterall, that is what I have, additional attributes to
the tag defining the data type it should accept. Too bad that was (is)
not in the xHTML spec.

I can only hope that the new spec with xFORMS will allow such
definitions. If not, I'll (slightly) modify my library to process
xFORMS, add my attributes to the FORM Objects and get on going.

Thanks for your point. I'm sure many will/do follow it. It just smacks
of "after-thought" to me.

walter