form.vars appear only after form.process()  call (process() - 
filter/convert/format/validate request.vars to form.vars)
you have variants :
1. *before *form creation  - modify field.default
2. *before* form.process()  -  modify request.vars - 
request.vars.PostDate=... 
3. pass your own set of vars  -  form.process(vars=myvars)
4. use form.process( onvalidation=myvalidation_fun) to modify form.vars  *after 
*basic validation passed
 

On Thursday, January 19, 2017 at 10:31:15 PM UTC+3, Dave S wrote:
>
>
> I have a straight-forward controller function for entering the primary 
> data:
>
> def index():
>     """
>     """
>     response.flash = T("Hello World")
>     form = SQLFORM(db.QuarterMaster)
>     form.vars.PostDate = str(request.now.year) + "-" + str(request.now.
> month) + "-" + str(request.now.day)
>     if form.process().accepted:
>         form.vars.PostDate = request.vars.PostDate
>         response.flash = T("Thank you!")
>     elif form.errors:
>         response.flash = T("Please correct the errors in the form")
>     else:
>         response.flash = T("Please fill out the form")
>     return dict(form=form)
>
>
> The intial display of the form shows the current date correctly (give or 
> take a leading 0), but after submission the PostDate field is empty.  I 
> would like to have it default to what was used the previous time through, 
> but it appears that value is dropped after the accepted branch.  What do I 
> need to do?
>
> It does not work to replace the top part with:
>
>     form = SQLFORM(db.QuarterMaster)    if request.vars.PostDate:
>       form.vars.PostDate = request.vars.PostDate
>     else:
>       form.vars.PostDate = str(request.now.year) + "-" + str(request.now.
> month) + "-" + str(request.now.day)
>     if form.process().accepted:
>         # here was form.vars.PostDate = request.vars.PostDate
>
> Thanks.
>
> Dave
> /dps
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to