An Niphlod implies,

session.forget()

breaks the form logic. Unless you do form.process(session=False)



On Thursday, 13 September 2012 13:43:30 UTC-5, Luis Furtado wrote:
>
> Hello,
> When I submit the form no validation errors are shown and, after a few 
> seconds, it just shows the form again, totally blank even if I had filled 
> some fields.
> If I include @auth.requires_login() at index() it even gets back to login 
> instead of the form.
> It seems as if the application is restarted when it tries to do the 
> validation phase.
>
> ------------------- MODEL --------------------
> db = DAL('sqlite://storage.sqlite')
>
> db.define_table( 'concelho',   Field('codigo'),   Field('nome'),    
>  format='%(nome)s')
>
> db.define_table( 'freguesia',
>    Field('cod_concelho', requires= IS_IN_DB( db, db.concelho.codigo )),
>    Field('codigo'),
>    Field('nome'),  
>    format='%(nome)s'
> )
>
> db.define_table( 'r',
>    Field('user_id', 'integer'),
>    Field('municipio', requires= IS_IN_DB( db, db.concelho.codigo, 
> '%(nome)s')),
>    Field('freguesia', requires= IS_IN_DB( db, db.freguesia.codigo, 
> '%(nome)s')),
>    Field('morada', requires= IS_NOT_EMPTY()),
>    Field('cod_postal', requires= IS_MATCH('^\d{4}-\d{3}$')),
>    Field('nif', requires= IS_MATCH('^\d{9}$')),
>    Field('nat_juridica', requires= IS_IN_SET(['AUT','EMP','SOC'])),
>    Field('ini_agricola', 'integer', requires= IS_EMPTY_OR( 
> IS_INT_IN_RANGE( 1970, 2012))), 
>    Field('p_nome', requires= IS_NOT_EMPTY()),
>    Field('nascimento', 'date', requires = IS_EMPTY_OR( IS_DATE( 
> format='%Y-%m-%d'))),
>    Field('escolaridade', requires = 
> IS_IN_SET(['Básico','Secundário','Licenciatura','Mestrado']))
> )
>
> db.define_table( 'prod',
>    Field('r_id', db.r ),
>    Field('codigo', 'integer',label='Espécie', requires= IS_NOT_EMPTY()),
>    Field('cmr_convenc', 'integer',label='Convencional', requires= 
> IS_NOT_EMPTY()),
>    Field('cmr_mpb', 'integer',label='M.P.Biológico',requires= 
> IS_NOT_EMPTY())
> )
> ------------------ CONTROLLER -----------------
> def index():
>    session.forget()
>    session.r_id = 40 # Initial value -- will be replaced by form.vars.id
>
>    form = SQLFORM( db.r)
>    if form.process( next=URL('f_prod') ).accepted:
>       session.r_id = form.vars.id
>       response.flash = 'Success (R_ID=%s)' % session.r_id
>    elif form.errors:
>       response.flash = 'ERRORS in the form'
>    else:
>       response.flash = 'Form 1 of 2'
>
>    return dict( form=form)
>
>
> def f_prod():
>
> RID = session.r_id
>
> form = SQLFORM( db.prod)
> if form.process().accepted:
>    response.flash = 'Success'
> elif form.errors:
>    response.flash = 'ERRORS'
> else:
>    response.flash = 'Form 2 of 2'
>
> return dict( form=form, RID=RID)
> ---------------------------------
> What's wrong?
> Thanks
> Luis
>
>

-- 



Reply via email to