Error in Custom Register Page in web2py

139 views
Skip to first unread message

Akash Agrawall

unread,
Jan 3, 2014, 12:15:56 AM1/3/14
to
Hie folks..... When I click on submit button of the CUSTOM REGISTRATION form..... it redirects to the same page...... ?? No idea what this is about......
Controller: default.py
def register():
        form=auth.register()
        form.add_button('Cancel', URL('register'))
        if form.accepts(request.vars,session):
                print "did it"
                response.flash="Your Registration request has been successfully submitted"
                redirect(URL('home'))
        elif form.errors:
                response.flash="Errors in form"
        else:
                response.flash="nothing mah badd"
        return dict(late=late, form=form)

View: register.html
{{extend 'layout.html'}}
<a href={{=URL('home')}}>Home</a> » Book Connect
<p style="font-family:Times New Roman;font-size:17px;">
We facilitate sharing of books with partner Schools, NGOs, community centers, and shelter homes.
<br/><br/>
In case  you represent any of the above, please register with us as partner to avail our book sharing program BookConnect. Once registered with us, you can search through our book repository and request for the books.
</p>
<br/>
{{=form.custom.begin}}
<table>
<tr>
    <td style="width:51%;">Name&nbsp;<span style="color:red;">*</span></td><td> {{=form.custom.widget.Name}}</td>
</tr>
<tr>
    <td style="width:51%;">Email&nbsp;<span style="color:red;">*</span></td><td> {{=form.custom.widget.email}}</td>
</tr>
<tr >
<td style="width:51%">Password&nbsp;<span style="color:red;">*</span></td><td> {{=form.custom.widget.password}}</td>
</tr>
<tr>
<td style="width:45%">Address&nbsp;<span style="color:red;"></span></td><td> {{=form.custom.widget.Address}}</td>
</tr>
<tr>
<td style="width:45%">Contact Person&nbsp;<span style="color:red;"></span></td><td>{{=form.custom.widget.Contact_person}}</td>
</tr>
<tr>
<td style="width:45%">Contact No 1&nbsp;<span style="color:red;">*</span></td><td>{{=form.custom.widget.Contact_No_1}}</td>
</tr>
<tr>
<td style="width:45%">Contact No 2&nbsp;<span style="color:red;"></span></td><td>{{=form.custom.widget.Contact_No_2}}</td>
</tr>
<tr>
<td style="width:45%">Description&nbsp;<span style="color:red;"></span></td><td>{{=form.custom.widget.Description}}</td>
</tr>
<tr>
<td style="width:45%">Website&nbsp;</td><td>{{=form.custom.widget.Website}}</td>
</tr>
<tr>
<td style="width:40%">Date of Request</td><td>{{=form.custom.widget.Date_of_request}}</td>
</tr>
<tr style="visibility:hidden"><td style="width:40%">Status</td><td>{{=form.custom.widget.Date_of_request}}</td></tr>
<tr><td>{{=form.custom.submit}}
   <!--a class="btn btn-default" href={{=URL('donate_book')}}>Cancel</a--></td></tr>
</table>
{{=form.custom.end}}


print form.errors -> <Storage {}>
pritn form.accepts(request.vars,session) -> false

Anthony

unread,
Dec 31, 2013, 10:03:54 AM12/31/13
to web...@googlegroups.com
At the end of the form, you have {{=form.custom.begin}}, but it should be {{=form.custom.end}}.


On Tuesday, December 31, 2013 7:24:34 AM UTC-5, Akash Agrawall wrote:
Hie folks..... When I click on submit button of the CUSTOM REGISTRATION form..... it redirects to the same page...... ?? No idea what this is about......
Controller: default.py
def register():
        form=auth.register()
        form.add_button('Cancel', URL('register'))
        form=auth.register()
{{=form.custom.begin}}

Akash Agrawall

unread,
Jan 2, 2014, 5:30:54 AM1/2/14
to web...@googlegroups.com
Thanks for marking that error..... but after changing that also same error..... :( .... it's urgent...

Anthony

unread,
Jan 2, 2014, 10:25:07 AM1/2/14
to web...@googlegroups.com
Sorry, hadn't looked closely at the controller code. First, your first two lines are useless, as the third line simply overwrites the "form" variable with a completely new object. Second, auth.register() already handles the form processing, so you cannot subsequently call form.accepts(). If you want to control the flash messages, use the auth.messages object to set them.

Anthony

Akash Agrawall

unread,
Jan 3, 2014, 12:19:52 AM1/3/14
to web...@googlegroups.com
Yaa thanx for pointing that out...... have removed the 3rd line.... it would be much helpful if you can explain the usage of auth.message ....

Akash Agrawall

unread,
Jan 3, 2014, 12:38:21 AM1/3/14
to web...@googlegroups.com
Also if I remove the controller's flash line i.e. my new controller is:

Controller: default.py
def register():
        form=auth.register()
        form.add_button('Cancel', URL('register'))
        return dict(form=form)
Still it doesn't work.... i.e. it redirects to register.html with the data entered(which I filled in before clicking on register button).... and doesn't enter it into the database.....

Akash Agrawall

unread,
Jan 3, 2014, 9:01:39 AM1/3/14
to web...@googlegroups.com
Have to define all the attributes in custom form.... otherwise it won't run... wasn't doing the same..... define it as hidden if you don't want user to see them..... !!


On Tuesday, December 31, 2013 5:54:34 PM UTC+5:30, Akash Agrawall wrote:
Hie folks..... When I click on submit button of the CUSTOM REGISTRATION form..... it redirects to the same page...... ?? No idea what this is about......
Controller: default.py
def register():
        form=auth.register()
        form.add_button('Cancel', URL('register'))
{{=form.custom.end}}

Anthony

unread,
Jan 3, 2014, 11:29:51 AM1/3/14
to web...@googlegroups.com
No, it's better to set the readable and writable attributes to False if you want particular fields to be excluded from the form.

    for fields in ['field1', 'field2', 'field3']:
        db
.auth_user[field].readable = db.auth_user[field].writable = False
    form
= auth.register()

Anthony

Akash Agrawall

unread,
Jan 3, 2014, 12:24:14 PM1/3/14
to web...@googlegroups.com
true that... this one is better..


--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/UtyexKmQpZY/unsubscribe.
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.



--
akash.wanteds
Reply all
Reply to author
Forward
0 new messages