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
On Tue, Mar 05, 2002 at 09:19:16AM -0700, Mike Tran wrote:
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.
Actually this is not true. Consider the following kind of dtml <form method=post action=.> <dtml-if "error_message"> <font color=red><dtml-var error_message></font> </dtml-if> The usual rest of form. </form> validation does require a round trip to server, but does not require changing pages, at all. Certain early version of mozilla got confused by this. If you use javascript, you are making some assumptions about the browsers being used, and the willingness of users to accept risk, and the absence of firewalls between you and your audience. In particular, see http://security.greymagic.com/adv/gm001-ie/ Perhaps this risk is acceptable to you, perhaps the limitation of audience is acceptable to you. But necessity is not a reason to use javascript in this case (although it may be more convenient to you). Jim Penny
Thanks,
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 )
I realise that you have some answers for your question. But I belive you are not looking for a Zope form validating solution, and you want to fix what you've made in Javascript. Esentialy, there's no problem with javascript inside Zope, and there's no problem with javascript form validating in zope. I've copy-paste your form and made a Test "insertResume" method and have no problem with it. Keep tying or give us more information (insertResume method for example) Andrés Sánchez Gómez EcMess.com
Well, the "insertResume" method call on another method to Insert the data into a database <dtml-call SQLinsertResume> and uses <sendmail> to notify the site adminstrator. I did not have any problems with Jscript inside of Zope. My problem was form data did not get passed to "insertResume". Inside the SQLinsertResume and sendmail I have variables referencing the form. Zope gave me an error because those form data was not passed to "insertResume". Error Type: KeyError Error Value: age On Tue 05 Mar 02 10:34, you wrote:
I realise that you have some answers for your question. But I belive you are not looking for a Zope form validating solution, and you want to fix what you've made in Javascript. Esentialy, there's no problem with javascript inside Zope, and there's no problem with javascript form validating in zope. I've copy-paste your form and made a Test "insertResume" method and have no problem with it. Keep tying or give us more information (insertResume method for example)
Andrés Sánchez Gómez EcMess.com
-- Mike Doanh Tran Shuffle Master Gaming Inc.
You've try to print <dtml-var age> in the "insertResume" method? May be the problem is not in the form-to-insertResume step. How do you call the age (and the other form vars) from the SQLinsertResume and sendmail methods? Andrés Sánchez Gómez EcMess.com Mike Tran wrote:
Well, the "insertResume" method call on another method to Insert the data into a database <dtml-call SQLinsertResume> and uses <sendmail> to notify the site adminstrator.
I did not have any problems with Jscript inside of Zope. My problem was form data did not get passed to "insertResume". Inside the SQLinsertResume and sendmail I have variables referencing the form. Zope gave me an error because those form data was not passed to "insertResume".
Error Type: KeyError Error Value: age
On Tue 05 Mar 02 10:34, you wrote:
I realise that you have some answers for your question. But I belive you are not looking for a Zope form validating solution, and you want to fix what you've made in Javascript. Esentialy, there's no problem with javascript inside Zope, and there's no problem with javascript form validating in zope. I've copy-paste your form and made a Test "insertResume" method and have no problem with it. Keep tying or give us more information (insertResume method for example)
Andrés Sánchez Gómez EcMess.com
participants (4)
-
Andrés Sánchez Gómez -
Jim Penny -
Mike Tran -
Trevor Toenjes