Hi Artman,
On Jul 18, 8:02 am, 陶艺夫 <[email protected]> wrote:
> the table:
> db.define_table('users',
> SQLField('user_name','string',required=True,unique=True),
> SQLField('password','password',length=80,required=True),
> SQLField('town_id','integer'), # this can be NULL
> SQLField('name','string',required=True),
> SQLField('gender',requires=IS_IN_SET(['male','female'])),
> SQLField('telephone','string'),
> SQLField('cellphone','string'),
> SQLField('grade','integer',default=3) #user's grade, 1-admin 2-normal
> 3-viewer
> )
>
> the action:
> def add_user():
> ...
> # print response.vars I CAN see the storage returned contains the
> correct information .
> form=form(db.users,formname=None):
> if form.accepts(request.vars,session):
> response.message='User added!'
> elif form.errors:
> response.message='There are some errors when adding user to the
> database!'
> else:
> response.message='Please filling the form.'
> return dict()
>
> the view:
> ....
> <input type="text" id='users_user_name' name='user_name' value=''/>
> ...
> <select id="users_grade" name="grade">
> <option value='1'> admin</option>
> ...
> </select>
> ....
>
> Thank Massimo for your GREAT work! :)
>
you have several errors in the the action (in fact it won't even run
as shown) but the main problem is in the view, you don't have the
form's hidden fields so the accepts will always fail. To fix do:
In the action change:
1) form=form(...) to form=SQLFORM(...)
2) all response.message to response.flash
3) return dict() to return dict(h=form.hidden_fields())
In the view add:
{{=h}}
somewhere inside your custom form,
that will create the required hidden fields.
If you have the book look up "hidden fields".
Denes.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---