Here's my example servlet (named Login2). Pretty simple I think but I'm
still managing to screw up royally.
To demonstrate, load up the servlet, enter something other than "pass" as
the password. Be amazed as no form containing the error is then returned.
I appreciate the help.
- I.
from WebKit.Page import Page
from Cheetah.Template import Template
from eSitePage import eSitePage
from FunFormKit.Form import FormServlet, FormDefinition
from FunFormKit import Field
from FunFormKit.Validator import ValidatorConverter, FormValidator, \
InvalidField
from WebUtils.Funcs import htmlEncode
class ValidateForm(FormValidator):
def validate(self, fieldDict):
if fieldDict["password"] != "pass":
return {"password": "Incorrect password"}
formDef = FormDefinition('Login2', 'writeForm',
[Field.TextField('userid',
maxLength=40,description='User ID'),
Field.PasswordField('password', size=10,
maxLength=20),
Field.SubmitButton('submit', description='Login',
methodToInvoke='login'),
],
formValidators=[ValidateForm()])
the_template = "<html><head></head><body>$content</body></html>"
class Login2(Page, FormServlet):
def __init__(self):
FormServlet.__init__(self, 'getForm', [formDef])
Page.__init__(self)
#Get template
self.template = Template(the_template)
def writeHTML(self):
self.template.content = self.getContent()
self.write(self.template)
def writeForm(self):
return self.renderableForm().htFormTable(bgcolor="#ddddff")
def login(self, fields):
self.writeln("You are logged in")
def getContent(self):
x = self.getForm()
# if not x: x = self.writeForm()
return x
def getForm(self):
return self.writeForm()
-----Original Message-----
From: Aaron Held [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 04, 2002 2:54 PM
To: Ian Sparks; 'Ian Bicking'
Cc: Webware-Discuss "(E-mail)
Subject: Re: [Webware-discuss] FunFormKit : 2nd Attempt.
I think that I am missing the problem.
the line
FormServlet.__init__(self, 'getForm', [formDef])
should be told what is the content method to override to for that
page to be displayed.
The idea is if the servlet is called without the parameters (I
think it looks for __formname__ or somthing like that) then the
method will be overridden with the the FFK method called
writeForm.
If the form is called w/ parameters and the values pass
vaildation then the content method is overridden with the method
that you tied to the action in your form def. So in your case
you are filling getForm with the contents of the method login.
Think of it this way.
The content method mentioned in FormSErvlet.__init__ is the
content 'block' that you would like FFK to manage.
So you should not use getForm unless getForm is the content area
in your page that you wish to fill with the form.
Can you send me the servlet?
Thanks,
-Aaron Held
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss