Your ifs are not properly nested but I think you want:
if form.accepts(request.vars, session):
#code to insert the record here
elif form.errors:
response.flash = 'Form has errors'
And why are you using factory?.
If you want to have control over the DB insertion do:
form = SQLFORM(db.traveler_template,record=record,dbio=False)
and then you have to do the insert (and presumably other stuff) inside
your accepts.
On Feb 28, 4:17 pm, Lennon <[email protected]> wrote:
> I think I must be missing something obvious.
>
> The form displays correctly and populates with the record/data that I
> want it to populate with. But when I hit the submit button, it won't
> run the code under "if form.accepts". It just reloads the page with
> the same form and record and no insert has been done or error message
> given.
>
> rows = db(db.traveler_template.user_id == session.user['id']).select()
> record = rows[0]
> form = SQLFORM.factory(db.traveler_template,record=record)
>
> if form.accepts(request.vars, session):
> #check whether the form had errors
> if form.errors:
> response.flash = 'Form has errors'
> return dict(form=form)
> else:
> #insert the record
> | Insert Code Omitted |
>
> return dict(form=form)
>
> I also tried
>
> if form.accepts(request.vars):
>
> to no avail.
>
> Also, I'm using the {{=form.custom.begin}} type syntax to display the
> form. Could that have something to do with it?