Hi Brian

One rather low-level way to add a field to a SQLFORM would be
something like this:

myinput = INPUT(_type='checkbox',_name='test')
f = SQLFORM(db.job_post)
f[0].insert(len(f[0])-1,myinput)

See also this post from Bruno:

http://groups.google.com/group/web2py/msg/41fbeda903c71f3f

There are probably better methods to deal with this. When we have
established the best way, we should put this in the book.

Regards,  David

On Mar 27, 11:43 am, Brian Will <[email protected]> wrote:
> I have an insert SQLFORM of 8 fields, to which I'd like to add a
> single "I agree to terms" checkbox at the bottom. There are probably
> tons of ways to do this, but I'm hoping someone has a really simple
> method that doesn't require resorting to a manual FORM? Can I simply
> tack on another INPUT to the SQLFORM? (Bonus points for placing it
> after my last field but before the submit button). Here's the current
> code.
>
>     form = SQLFORM(db.job_post, submit_button='Post Job',
> formstyle='table2cols',
>         fields=['poster_name', 'poster_email', 'poster_phone',
> 'zipcode', 'location_description', 'job_type', 'job_title',
> 'job_description'],
>         _id='postjob'
>     )
>
>     if form.accepts(request.vars, session):
>         redirect(URL('post_email', vars={'id': form.vars.id,
> 'poster_name': form.vars.poster_name, 'poster_email':
> form.vars.poster_email}))
>
> What's solution allows me to make the minimal change? The simplest
> solution that occurs to me is to use a SQLFORM.factory:
>
>     form = SQLFORM(db.job_post.poster_name, db.job_post.poster_email,
> db.job_post.poster_phone, db.job_post.zipcode,
> db.job_post.location_description, db.job_post.job_type,
> db.job_post.job_title, db.job_post.job_description, FIELD('terms',
> 'boolean', IS_EQUAL_TO(True)) submit_button='Post Job',
> formstyle='table2cols',
>         _id='postjob'
>     )
>
>     if form.accepts(request.vars, session):
>         form.vars.id =
> db.job_post.insert(**db.job_post._filter_fields(request.vars))
>         redirect(URL('post_email', vars={'id': form.vars.id,
> 'poster_name': form.vars.poster_name, 'poster_email':
> form.vars.poster_email}))
>
> I guess this isn't too onerous, but I don't really like having to
> manually do the insert, so I'm wondering about alternatives. BTW, why
> does _filter_fields begin with _ if it's used publicly? Shouldn't it
> just be filter_fields?

Reply via email to