Hi Yannick,

Your code sample showing how to access the hidden fields of the form
object gave me the clue I needed to fix my custom form posting to the
auth login url.


For those wondering how to do the same, here is an example:

controllers/default.py
def index():
    response.flash = T('Welcome to web2py')
    return dict(message=T('Hello World'),authForm=auth.login())


views/index.html:

<!-- this form posts to /<your application name>/auth/user/login -->
<form id="form_login" enctype="multipart/form-data" action="{{=URL
(r=request,c='auth',f='user',args='login')}}" method="POST">
Username: <input name="username" type="text" />
Password: <input name="password" type="password" />
{{=authForm.hidden_fields()}}
</form>

Thanks.

On May 24, 7:34 pm, Yannick <ytchatch...@gmail.com> wrote:
> Hello Mate,
>
> I have a page called "index.html" with several form inside... here is
> a sample of my code:
> ##################
> #Controller:
> ##################
>
> @auth.requires_login()
> def pwdSetting():  return dict(chg_pwd = auth.change_password())
>
> @auth.requires_login()
> def profileSetting():
>  # Some code here where I defined: default_firstname and
> default_lastname
> settingform = FORM('First Name:', INPUT(_name='firstname',
> requires=IS_NOT_EMPTY(), value= "%s"%default_firstname),
>                        'Last Name:', INPUT(_name='lastname',
> requires=IS_NOT_EMPTY(), value= "%s"%default_lastname),
>                        INPUT(_type='submit') )
> .....
>  if FORM.accepts(settingform, request.vars, session, keepvalues=True):
>        # Some code here#
> .....
> return dict(formsetting=settingform)
>
> @auth.requires_login()
> def index():
>     profileSet = profileSetting()
>     pwdSetting = pwdSetting()
>     return dict( profileSet=profileSet, pwdSet=pwdSetting)
>
> ###########
> # index.html
> ###########
> Profile Setting:
> <form action="" enctype="multipart/form-data" method="post">
>      First Name:
>                <input name="firstname" type="text"
> value="{{=profileSet.latest.firstname}}"/>
>     Last Name:
>                <input name="lastname" type="text"
> value="{{=profileSet.latest.lastname}}"/>
>                 <input type="submit" value="Submit" />
>     ....
>     ....
>      {{=profileSet.hidden_fields()}}
> </form>
>
> Password Setting:
> <h1> Password Setting </h1>
>
> <form action="" enctype="multipart/form-data" method="post">
>    Old Password:
>         <input name="old_password" type="password" value="" />
>          New Password:
>         <input name="new_password" type="password" value="" />
>          Re-Type Password:
>         <input name="new_password2" type="password" value="" />
>         <input type="submit" value="Submit" />
>     {{=pwdSet.hidden_fields()}}
> </form>
>
> ############################################################
>
> When I do this i have an error message saying :
>                 "AttributeError: 'str' object has no attribute
> 'latest'"
>
> Does any one has an idea how to solve this problem... The way i design
> it i want to have each controller for each form... I can make this
> work by have a BIG controller 'Index' that define and return several
> form BUT this solution is difficult to maintain and may trigger a bad
> performance....
>
> Please let me know if you have any idea... Thank You.
>
> Yannick P.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to