Validating data entry (dates)
Hi, Is there an elegant way to validate fields in a form before submitting. For example: I have a date field. I want to check, before submitting the form, if the date entered is valid. Is there someting like a function as: Date.IsValid (I haven a Delphi background). What I don't want is a Zope generated standard error screen. I want a custom designed error message/page. thanks, Henny van der Linde
hi henny, my suggestion for data validation *before* submitting the form would be javascript. (is that blasphemy??? ;) DTML is interpreted on the server, so you would not be able to validate using DTML without sending the data back to the server... jens
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Henny van der Linde Sent: Wednesday, December 08, 1999 18:14 To: Zope mailing list Subject: [Zope] Validating data entry (dates)
Hi,
Is there an elegant way to validate fields in a form before submitting.
For example:
I have a date field. I want to check, before submitting the form, if the date entered is valid. Is there someting like a function as: Date.IsValid (I haven a Delphi background). What I don't want is a Zope generated standard error screen. I want a custom designed error message/page.
thanks,
Henny van der Linde
Hi Jens,
my suggestion for data validation *before* submitting the form would be javascript. (is that blasphemy??? ;)
Blasphemy no (for me at least;) I was hoping that i could avoid Javascript. Mixing DTML and Javascript for such a simple task seems to me a bit messy.
DTML is interpreted on the server, so you would not be able to validate using DTML without sending the data back to the server...
Shame om me, that's something I completly overlooked. That said it would be nice if you can evaluate the outcome of a form submit, trapping errors. Something like (Delphish pseudocode): if form.submit.errocode <> 0 {an error accured) then begin case errorcode of begin 00001: ShowMessage('InvalidDate'); end; end Henny van der Linde
On Thu, 9 Dec 1999, Henny van der Linde wrote:
I have a date field. I want to check, before submitting the form, if the date entered is valid. Is there someting like a function as: Date.IsValid (I haven a Delphi background). What I don't want is a Zope generated standard error screen. I want a custom designed error message/page.
There are two options really: 1) Write nifty JavaScript to validate at the client before submitting to the server. This code doesn't exist in a general Zope form, but lots of us would like it :-) 2) Use <dtml-try> <dtml-except> clauses in the DTML method that accepts your form input, so if an exception is thrown converting a submitted string to a date, for instance, you can display a nice error message. -- ___ // Zen (alias Stuart Bishop) Work: zen@cs.rmit.edu.au // E N Senior Systems Alchemist Play: zen@shangri-la.dropbear.id.au //__ Computer Science, RMIT WWW: http://www.cs.rmit.edu.au/~zen
HERE IS SOME JAVASCRIPT I USE TO VALIDATE DATES ON THE CLIENT SIDE function JValiDate(dateStr){ if (dateStr.length==0){ dateStr='99/99/9999'; } else if (dateStr.charAt(0)==' '){ dateStr='99/99/9999'; } while (dateStr.charAt(dateStr.length-1)==' ') dateStr=dateStr.substring(0,dateStr.length-1); var dtmp=''; var z='' for (var x=0; x < dateStr.length; x++) { z=dateStr.charAt(x); if (z>=0 && z<=9) { dtmp+=z; } else dtmp+='/'; } if (dtmp.charAt(1)=='/') dtmp='0'+dtmp; if (dtmp.charAt(4)=='/') dtmp=dtmp.substring(0,3)+'0'+dtmp.substring(3,dtmp.length); // alert ('>'+dtmp+'<'); // alert (dtmp.length); if (dtmp.length==8){ tyear=dtmp.substring(6,8); // alert(tyear) if (tyear<31) { dtmp=dtmp.substring(0,6)+'20'+tyear } else { dtmp=dtmp.substring(0,6)+'19'+tyear; } } var a=dtmp var err=0 var psj=0; if (a.length != 10) err=1 var b = a.substring(0, 2)// month var c = a.substring(2, 3)// '/' var d = a.substring(3, 5)// day var e = a.substring(5, 6)// '/' var f = a.substring(6, 10)// year // basic error checking if (b<1 || b>12) err = 1 if (c != '/') err = 1 if (d<1 || d>31) err = 1 if (e != '/') err = 1 if (f<1900 || f>2099) err = 1 // advanced error checking // months with 30 days if (b==4 || b==6 || b==9 || b==11){ if (d==31) err=1 } // february, leap year if (b==2){ // feb var g=parseInt(f/4) if (isNaN(g)) { err=1 } if (d>29) err=1 if (d==29 && ((f/4)!=parseInt(f/4))) err=1 } if (err==1){ if (dateStr!='99/99/9999'){ alert('Date '+dtmp+' is not valid!'); } return '' } else { return dtmp; } } HERE IS EXAMPLE OF USE <input type="text" name="wpodate" size="9" maxlength="10" value="<dtml-var "podate.toZone('US/Central').strftime('%m-%d-%Y')">" onChange="this.value=JValiDate(this.value)"> __________________________________________________________________ Jim Sanford . Database Engineer / \ / Accelerated Technology, Inc. / / 720 Oak Circle Drive East / / \ Mobile, AL 36609 / / \ Voice: 334-661-5770 fax: 334-661-5788 / \ E-Mail: jsanford@atinucleus.com Web: http://www.atinucleus.com Source Code, No Royalties, Any CPU...It just make sense ! __________________________________________________________________ ----- Original Message ----- From: Henny van der Linde <linde@inline-info.nl> To: Zope mailing list <zope@zope.org> Sent: Wednesday, December 08, 1999 5:13 PM Subject: [Zope] Validating data entry (dates) Hi, Is there an elegant way to validate fields in a form before submitting. For example: I have a date field. I want to check, before submitting the form, if the date entered is valid. Is there someting like a function as: Date.IsValid (I haven a Delphi background). What I don't want is a Zope generated standard error screen. I want a custom designed error message/page. thanks, Henny van der Linde _______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope No cross posts or HTML encoding! (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (4)
-
Henny van der Linde -
Jens Vagelpohl -
Jim Sanford -
Stuart 'Zen' Bishop