First, I think you want FORM(INPUT(_name='n')), otherwise you'll have an
empty form.
If you want to pre-populate a form using form.vars.fieldname=somevalue, you
have to do that after the form is created, but *before* you call
form.accepts (the form.accepts method adds the form.vars value to the INPUT
element). See
http://web2py.com/book/default/chapter/07#Pre-populating-the-form.
If you only want to pre-populate the field after a failed form submission
(but not when the form is initially loaded), then you could use an
alternative method:
form.element(_name='n').update(_value='MY DYNAMIC VALUE')
That updates the html INPUT element directly instead of relying on
form.accepts to add the form.vars value to the element.
Anthony
On Saturday, June 25, 2011 2:15:57 AM UTC-4, mweissen wrote:
> Hi,
>
> let's say I have a simple form like the following:
>
> def one():
>
> form = FORM(_name='n')
>
> if form.accepts(request.vars, session):
>
> # do something
> redirect(URL('two'))
>
> else:
>
> *# what I want to do is something like*
>
> *form.vars.n = 'MY DYNAMIC VALUE'*
>
>
> return dict(form=form)
>
>
> Regards, Martin
>
>