SQLFORM.factory form.process().accepted not behaving as expected

619 views
Skip to first unread message

Jim S

unread,
Mar 13, 2013, 11:29:07 AM3/13/13
to web...@googlegroups.com
I have the following code:

form = SQLFORM.factory(Field('auth_group', 'integer', label='Groups', required=True), formname='membership', submit_button='Add Membership')

if form.process().accepted:
   user_update
= form.vars
   
if user_update['auth_group'] and user_update['auth_group'] != '0':
       db
.auth_membership.insert(user_id=userId, group_id=user_update['auth_group'])

   redirect
('#')





When I click on my add button it refreshes the page, but nothing else happens.  It never gets past the form.process().accepted:

I've been staring at this for an hour and can't see what I'm doing wrong.  What am I not seeing?

-Jim

Anthony

unread,
Mar 13, 2013, 11:51:47 AM3/13/13
to web...@googlegroups.com
Not sure if this is the problem, but formname is an argument of .process(), not .__init__().

Anthony

Jim Steil

unread,
Mar 13, 2013, 12:11:48 PM3/13/13
to web...@googlegroups.com
Thanks Anthony.  If I put formname='membership' in the form.process().accepted like this:

form.process(formname='membership').accepted:

Then does that refer to the _id arg set by SQLFORM.factory(_id='membership')???

-Jim



--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/8p1jHtpxJNU/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Niphlod

unread,
Mar 13, 2013, 12:15:55 PM3/13/13
to web...@googlegroups.com
nope. formname "overrides" the hidden field value _formname

Jim Steil

unread,
Mar 13, 2013, 12:58:16 PM3/13/13
to web...@googlegroups.com
Thanks

Anthony

unread,
Mar 13, 2013, 1:18:43 PM3/13/13
to web...@googlegroups.com
The main reason for setting your own formname is if you have more than one form on the same page that would otherwise be assigned the same default name by SQLFORM.

Anthony

Jim S

unread,
Mar 13, 2013, 1:52:45 PM3/13/13
to web...@googlegroups.com
I think I've gotten to the bottom of my problem.  I was using a custom form to display the form created in my controller.  And yes, there are numerous forms on this page.  And, this form is in a LOADed component using AJAX.  

If I use this for the custom form definition:

<table>
 {{=form.custom.begin}}
   
<tr>
     
<td>
       {{=form.custom.label.site}}
     
</td>
     
<td>
       {{=form.custom.widget.site}}
     
</td>
     
<td>
       {{=form.custom.submit}}
     
</td>
   
</tr>
 {{=form.custom.end}}
 
<tr>
     
<td></td>
     
<td>
       {{=grid}}
     
</td>
     
<td></td>
 
</tr>
</table>





Notice that my form.custom.begin/end are weirdly intersperse within my table.  If I take them out and put them outside the <table></table> elements then it works fine.  

Thanks, I do appreciate you all taking time to look at the code.  Too bad I didn't show you the right code.....

-Jim
Reply all
Reply to author
Forward
0 new messages