[Zope] Validating Form Data

Mike Tran mtran@shufflemasterrd.com
Tue, 5 Mar 2002 09:19:16 -0700


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