Zope doesn't do client-side validation like Javascript. I you want server side validation, try Formulator. ) It has built in handling of validation and error handling. And join the Formulator mailing-list. Or follow this pseudo-schema that has the form post to itself, and you do all your data handling with data in REQUEST. <dtml-if expr="REQUEST.REQUEST_METHOD=='POST'"> <dtml-try> <dtml-call "yourValidationscript(REQUEST)"> <dtml-except> ## yourValidationscript returns errors <dtml-var yourerrorhandlingscript> ## displays the errors and repost the form <dtml-var yourHTMLform> <dtml-else> ## everything passed validation in yourValidationscript <dtml-var dosomethingwithData> </dtml-try> <dtml-else> ## Nothing has been 'POSTed', ## this is your first time through, so just present the HTML form <dtml-var yourHTMLform> </dtml-if> Cheers, -Trevor
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Mike Tran Sent: Tuesday, March 05, 2002 11:19 AM To: zope@zope.org Cc: lazug@lazug.org Subject: [Zope] Validating Form Data
I am using the Javascript below to validate data on my form. The part where it validate form data works fine. My problem is when I call on the method "insertResume", my form variables does not get passed. For example, on the form i have a textbox field called "age". I reference this in the "insertResume" method with <dtml-var age>, but the age variable does not get passed from the form to the "insertResume" method.
Does anyone have any idea on how to fix this or maybe show me how to validate form data in Zope? I've tried <dtml-unless> but the user have to go to another page and go back to the form itself to correct the data. With Javascript the user can stay on the same page.
Thanks,
<SCRIPT LANGUAGE="JavaScript"> <!-- function valid(form) { var field = form.age; var userAge = parseInt(field.value); if (!userAge) { alert("You must indicate your age."); return false; } else if (userAge >= 18) { alert("Thank your for your resume."); return true; } else { alert("You are only " + userAge + ". Try again when you are 18."); field.focus(); field.select(); return false; } } // --> </SCRIPT>
<FORM METHOD="POST" ACTION="insertResume" onSubmit="return valid(this)">
Your age:<BR><INPUT TYPE="text" NAME="age" SIZE="2"><BR> Desired Job:<BR><INPUT TYPE="text" NAME="job" SIZE="40"><BR> Resume:<BR><TEXTAREA NAME="resume" COLS="40" ROWS="5"></TEXTAREA><BR> <INPUT TYPE="submit" VALUE="Send Resume"> </FORM>
-- Mike
_______________________________________________ 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 )