user2775042
user2775042

Reputation: 509

Why my form values are not being submitted in web2py?

I have a simple form for log in purposes. I am a beginner in using web2py so i cant figure out why my form values are not being submitted.

This my controller function

def signup():
   form = SQLFORM(db.Membership).process()
   form.add_button('Back', URL('index.html'))

   if form.process().accepted:
        session.flash = 'form accepted'
        redirect(URL('index.html'))
   elif form.errors:
        response.flash = 'form has errors'
   else:
        response.flash = 'please fill the form'

   return locals()

This is my database

db.define_table('Membership',
    Field('userID', 'id'),
    Field('username', 'string',unique=True),
    Field('membershipType','string',default = "Member", label = T('Membership Type')),
    Field('name' , 'string',default='Admin'),
    Field('password', 'password'),
    Field('email' , 'string',default='[email protected]'),
    Field('cNum', 'integer',, label = T('Contact Number'))
    )

and this is the html

<section>
    <h2>Fill in the details to register</h2>


    {{=form}}



</section>

Like i said i am only a beginner so if please give any help possible. Thanks

Upvotes: 0

Views: 657

Answers (2)

Diogo Martins
Diogo Martins

Reputation: 937

There is no need for form = SQLFORM(db.Membership).process() just change it to form = SQLFORM(db.Membership)

def signup():
   form = SQLFORM(db.Membership)
   form.add_button('Back', URL('index.html'))

   if form.process().accepted:
        session.flash = 'form accepted'
        redirect(URL('index.html'))
   elif form.errors:
        response.flash = 'form has errors'
   else:
        response.flash = 'please fill the form'

   return locals()

By the way, my i ask why you're creating a new 'Membership' table ? Web2py Auth already deal with authentication and authorisation for you. Check Access Control at Web2py's book.

Upvotes: 0

Anthony
Anthony

Reputation: 25536

You are calling form.process() twice. The first call will actually do the processing and insert the record, and the second one will simply reset the CSRF token. As a result, the .accepted attribute will be False in the second case, and you won't get the redirect and success message. Change the first line to:

form = SQLFORM(db.membership)

Upvotes: 1

Related Questions