>
> p.s. Should i be adding something to my post to show that a question
>
> is solved, like they do on stackoverflow? i saw somebody do that on
> this forum and did not know if I should be doing the same.
>
Most people don't, but I suppose you could add [SOLVED] to the subject, or
something like that.
> MODEL:
>
> db.define_table('president',
> Field('name', 'string'))
>
> db.president.name.requires = IS_NOT_IN_DB(db, 'president.name')
>
>
> CONTROLLER:
>
> def test():
> message = ""
> form = FORM('Join President?', INPUT(_name='join',
> _type='radio'),
> INPUT(_name="name"), INPUT(_type='submit'))
> if form.process().accepted:
> db.president.insert(name=form.vars.name)
> return dict(form=form, message=message)
>
The FORM object doesn't know anything about your db table, and you haven't
defined any validators in your form INPUTs, so form.process() doesn't do
any validation. You have a couple options. First, INPUT() takes a
'requires' argument, just like Field(), so you could define your
IS_NOT_IN_DB validator there. Or, you can do your insert like this:
response = db.president.validate_and_insert(name=form.vars.name)
If there are any errors, they will be in response.errors and response.id
will be None -- otherwise, response.id will be the id of the inserted
record.
Note, the 'requires' argument to Field sets validators for form submissions
-- it does not affect regular insert() or update() methods on the table.
The validate_and_insert() and validate_and_update() methods were created to
enable use of the form validators without actual form processing.
Anthony