Instead of form.accepts() you can use form.validate() and then do your
own update. Then you do not need to pass unnecessary variables to the
view and back again.
form = SQLFORM(table, id)
if form.validate():
form.vars.mysecretvariable="whatever I want"
if not form.errors:
if not id:
id=table.insert(**dict(form.vars))
session.flash = "record inserted"
elif form.vars.get('delete_this_record',False):
db(table.id==id).delete()
session.flash = "record deleted"
else:
table[id].update_record(**dict(form.vars))
session.flash = "record updated"
On Nov 2, 3:11 am, Omi Chiba <[email protected]> wrote:
> Thank you for understanding me :)
> I tried but this code will set the default value if the field exist on
> the view.
>
> I made a simple example. I don't want to show field2 so it's excluded
> in view using custom form but want to store the value like 'BBB' or
> 'CCC' before it's inserted into table. This code just leave field2
> blank...
>
> model
> ------------------------
> db.define_table('mytable',
> Field('field1'),
> Field('field2'))
>
> controller
> ------------------------
> def index():
> form = SQLFORM(db.mytable)
>
> form.vars.field2 = 'BBB'
>
> if form.process().accepted:
> form.vars.field2 = 'CCC'
> session.flash = 'form accepted'
> redirect(URL('index'))
> elif form.errors:
> response.flash = 'form has errors'
> return dict(form=form)
>
> view
> ------------------------
> {{extend 'layout.html'}}
>
> {{=form.custom.begin}}
> Field1: {{=form.custom.widget.field1}}
> {{=form.custom.submit}}
> {{=form.custom.end}}
>
> On Nov 1, 6:58 pm, pbreit <[email protected]> wrote:
>
>
>
>
>
>
>
> > I believe in your controller, before form.process() (or form.accepts),
> > include:
>
> > form.vars.FFTSCD = 'aaa'