OK. So I removed what I had before (tables in a database) and moved to 
SQLFORM.factory. I now have this in my controller:

form = SQLFORM.factory(
        Field('is_tutor', 'boolean'),
        Field('image', 'upload', 
requires=IS_EMPTY_OR(IS_IMAGE(extensions=('jpeg', 'jpg', 'png', 'gif')))),
        Field('location', 'list:string', requires=IS_NOT_EMPTY()),
        Field('subjects', 'list:string', requires=IS_NOT_EMPTY()),
        Field('qualifications', 'list:string', requires=IS_NOT_EMPTY()),
        Field('biography', 'string', length=500),
        Field('hourly_rate', 'decimal(7,2)', requires=IS_NOT_EMPTY()),
        Field('modified_on', 'datetime', requires=IS_DATETIME(), 
writable=False, readable=False, default=request.utcnow),
        table_name='tutor')

so when the form is submitted, I now need to check if the field is_tutor is 
True. If it is, I need to add that info to the current logged user's 
information. Do I need to modify auth to do this? If so, how?

On Monday, December 3, 2012 3:16:45 PM UTC, Niphlod wrote:
>
> if it's checked the corresponding var would be True. 
> If the form is submitted the controller will receive that field as 
> request.vars.fieldname or as form.vars.fieldname if you are using a form. 
> When you "get to" the form.process() line the value has been already been 
> "shipped" to the database. You must act "before": there is the onvalidation 
> callback (but it's generally used for other things, like additional 
> validation).
>
> If you want to skip form processing at all (and possibly doing some other 
> custom logic) you can rely either on SQLFORM with process(dbio=False) or 
> with SQLFORM.factory..... in either case you'll have to build (or not, 
> depending on the checkbox) the corresponding create/update record "by hand" 
> (not so hard with e.g. SQLFORM.factory because generally your form.vars 
> would be ready to be inserted into the table if the form has the same 
> structure of the table itself, e.g. db.table.insert(**form.vars))
>
>
> On Monday, December 3, 2012 3:27:29 PM UTC+1, Daniele wrote:
>>
>> Hey guys, I'm wondering if there's a way from the controller to know 
>> whether a form's boolean field (checkbox) is selected or not. I only want 
>> to add the info in the form to the database if the checkbox is selected, 
>> otherwise the controller should not process that form.
>>
>> Thanks!
>>
>

-- 



Reply via email to