Form validation

52 views
Skip to first unread message

Lucas

unread,
Oct 31, 2025, 8:43:50 AM (13 days ago) Oct 31
to py4web
hello one and all,

below is some example code where I'm using Form and validation under that.  the form.errors work ok under the validation function thus displaying the appropriate message when set.

however, when I try to update the form.vars['some_field'] value under the validation function, it does not change the value of that field.  in the below example, the form.vars['plot_controller'] should add a '3' at the end of that field every time the form is submitted.

am I doing something wrong?  thank you in advance, Lucas

@action("questions")
@action.uses("questions.html", db, auth, T, session)
def questions():
    #code blah....
    qfrm = Form(db.questions, record=(qidi if (qidi > 0) else None), deletable=False, validation=chk_question)
    if qfrm.accepted:
        qidi = qfrm.vars['id']
        redirect(URL('questions', vars={'ridi':sR.id, 'qidi':qidi}, hash='sample'))
    elif qfrm.errors:
        flash.set(f'question errors: {qfrm.errors}')
    #code blah....
    return dict(etc....)

def chk_question(f):
    v, e = f.vars, f.errors
    #f.vars['plot_controller'] = 'NONE1' if isinstance(v['plot_controller'], str) and (v['plot_controller'].strip()[:4].lower() == 'none') else v['plot_controller']
    f.vars['plot_controller'] = str(f.vars['plot_controller'])+'3'
    #e['plot_controller'] = 'dude plot'
    return f

Massimo DiPierro

unread,
Nov 6, 2025, 2:17:04 AM (8 days ago) Nov 6
to py4web
You found a bug. I fixed it in master. Please help me verify it is indeed fixed.

Also notice that the chk_question(f) does not need return f since the return value is ignored.

Lucas

unread,
Nov 6, 2025, 10:28:13 PM (7 days ago) Nov 6
to py4web
well alright.  cool.  how do I download "it in master"?  or should I just wait until its under "pip install --upgrade py4web" update?

I always figured I didn't need to return f always imagining it was first passed to the validator by reference, in the old pointer terms.   alright.

Massimo DiPierro

unread,
Nov 6, 2025, 11:44:29 PM (7 days ago) Nov 6
to Lucas, py4web
My bad. I should post instructions about that. 

Anyway, I will release a new version including the change tomorrow.

--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/py4web/2a02e9cb-75b5-404e-a5a8-92b1baaa1fc5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages