CLIFFORD ILKAY wrote:

... in the writeContent() method

if self.form.fname.error():
self.writeln('''\t<tr><td class="errorLabel">Please enter a first name</td>''')
self.writeln('''\t<td class="errorField">%s</td></tr>''' % self.form.fname.tag())
else:
self.writeln('''\t<tr><td>%s</td>''' % self.form.fname.label())
self.writeln('''\t<td>%s</td></tr>''' % self.form.fname.tag())


self.writeln('''\t<tr><td>%s</td>''' % self.form.mname.label())
self.writeln('''\t<td>%s</td></tr>''' % self.form.mname.tag())


if self.form.lname.error():
self.writeln('''\t<tr><td class="errorLabel">Please enter a last name</td>''')
self.writeln('''\t<td class="errorField">%s</td></tr>''' % self.form.lname.tag())
else:
self.writeln('''\t<tr><td>%s</td>''' % self.form.lname.label())
self.writeln('''\t<td>%s</td></tr>''' % self.form.lname.tag())


Some comments:

In FK there is already stuff for error formatting. For example, if there's an error, the input tag will contain class="error" so you can mark that as "red" or something (look in the examples). Also, it's easier on your typing if you make a short-name reference to the form object in your local name space, like "f = self.form". Then you can just do f.lname.tag().

But there's nothing "wrong" with what you're doing; there's just already some plumbing for some of it.

This seems to work though I have a couple of questions about it.

1. When I click on the Submit button, if I do not enter a Middle Name, the form will not POST successfully. That is strange considering that Middle Name is not mandatory. If I enter anything in Middle Name, the form will POST. The only difference I can see between Middle Name and the other fields is that it is not mandatory and as such, I do not test for an error condition. How can I get the form to POST with a blank Middle Name field?

Hmm. That shouldn't happen. It's possible that it's getting confused by the lack of a Validator set declaration in the constructor of your field. IE,


   newForm.addField(Fields.TextField('mname',label="Middle Name"))

may have to be:

   newForm.addField(Fields.TextField('mname', [ ], label="Middle Name"))

If that's the case, that's a bad bug on our parts. Send me your actual code and I'll take a look.

2. I am using SQLObject to map the PostgreSQL tables to Python objects. I have that part prototyped and working. Once I get past the hurdle above, I have to transfer the contents of the form fields above to the Person object attributes. According to the Class Reference, I think I should be using self.form.value(fieldName) to do this. e.g.

if self.form.isSuccessful():
        newPerson = Person(
                firstName = self.form.value(fname),
                middleName = self.form.value(mname),
                lastName = self.form.value(lname),
        )

... where Person is a SQLObject class corresponding to a PostgreSQL table. Am I on the right track?

That will certainly work. Alternatively, you can poke at each field:

       newPerson = Person(
               firstName = self.form.fname.value(),
               middleName = self.form.mname.value(),
                 [etc]
       )

Or, better yet, just get the whole values bundle as a dictionary:

values  = self.form.values()

newPerson = Person( firstName=values['fname'], middleName=values['mname'] ) etc...





-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to