Hello Matt,
At 12:09 AM 21/06/2004 -0400, Matt Feifarek wrote:
>Hi Clifford.
>
>FormKit is 3rd party software, not included with Webkit, but I'm one of
>the two authors, so I'll answer.
I knew it was third party software and that you were one of the authors but
I could not find a mailing list for FormKit so I decided to post here.
Chances are high that FormKit users are WebWare users, though the converse
is not necessarily true.
>The form.dump() method is very very simple, and not really meant for
>permanent use. It's just to make sure that your form works. Of course, it
>/can/ be used, but it's ugly, as you noticed. We use it to make sure
>everything is okay, then replace the form output bits in our servlets with
>more hand-crafted code.
>
>Every field in a form has a set of accessor methods that you can pick at
>to lay out your form in a template or manually or however you wish:
>
>myfield.tag()
>myfield.label()
>myfield.error()
>myfield.value()
>
>and some others...
>
>Basically, you just want to set up your code in self.writeln() or
>whatever, and just grab onto the tag() text, and drop it into your page
>output wherever you wish.
Thank you for explaining this. Once you gave me the clue, I found an
example grepping through the Examples directory and managed to get my first
form working. I have excerpted relevant bits below for when someone else
comes along and asks the same question.
#############################
def writeContent(self):
if self.form.isSuccessful():
self.writeln('''<p>Form successfully posted
'%s'.</p>''' % self.form.values())
else:
self.writeln( self.form.startTags() )
self.writeln(self.form.startTags())
self.writeln('''<table>''')
if self.form.userID.error():
self.writeln('''\t<tr><td>Please enter a
valid user ID</td>''')
self.writeln('''\t<td>%s</td></tr>''' %
self.form.userID.tag())
else:
self.writeln('''\t<tr><td>User ID</td>''')
self.writeln('''\t<td>%s</td></tr>''' %
self.form.userID.tag())
if self.form.pw.error():
self.writeln('''\t<tr><td>Please enter a
valid password</td>''')
self.writeln('''\t<td>%s</td></tr>''' %
self.form.pw.tag())
else:
self.writeln('''\t<tr><td>Password</td>''')
self.writeln('''\t<td>%s</td></tr>''' %
self.form.pw.tag())
self.writeln('''\t<tr><td> </td>''')
self.writeln('''\t<td>%s</td></tr>''' %
self.form.button.tag())
self.writeln('''</table>''')
self.writeln( self.form.endTags())
#############################
It would be nice to have a way of not having to write the fiddly HTML bits,
whether using tables or DIV tags, and do something like:
self.writeln(self.form.userID.label())
self.writeln(self.form.userID.tag())
self.form.userID.label() and .tag() would expand out to either the
appropriate table row/cell tag or DIV tag. I guess this is what something
like Cheetah template is allegedly able to do, though I have not figured
out how to do that yet.
Regards,
Clifford Ilkay
Dinamis Corporation
3266 Yonge Street, Suite 1419
Toronto, Ontario
Canada M4N 3P6
Tel: 416-410-3326
|