In order to apply attributes to a custom form you have to change
form.custom.begin before.
The following code should work:
#view html
{{extend 'layout.html'}}
{{
# add class to form
form['_class'] = "form-horizontal"
# change form.custom.begin
form.custom.begin = XML("<%s %s>" % (form.tag, form._xml()[0]))
}}
{{=form.custom.begin}}
your content form
{{=form.custom.end}}
Moreover, if do you want a form with bootstrap layout you could simply add
formstyle='bootstrap" to the form via auth.settings.formstyle argument
http://web2py.com/books/default/chapter/29/09?search=auth#Settings-and-messages
avoiding
to customize manually the html of the form.
def login():
auth.settings.formstyle = 'bootstrap'
form = auth.login()
return dict(form=form)
and in the view
{{=form}}
Il giorno martedì 20 novembre 2012 02:58:37 UTC+1, Daniele ha scritto:
>
> Ah ok I just took a look at the HTML and saw that my code conflicts with
> what web2py is generating.
> Basically there's a form within a form being constructed, so it looks like
> this:
>
> <form class="form-horizontal"> <form action=""
> enctype="multipart/form-data" method="post">
>
> To avoid this, how can I tell web2py that the login form's style has to be
> form-horizontal?
> That way it can generate the HTML automagically.
> I tried the following in my controller but it's still not working:
>
> def login():
> form = auth.login()
> form['_class']='form-horizontal'
> return dict(form=form)
>
> I'd eventually also like to style the Login button and the "Remember me for X
> days" checkbox.
>
> Thanks!
>
>
>
> On Wednesday, August 15, 2012 6:51:12 AM UTC+1, shartha wrote:
>>
>> Hello,
>> Quick question:
>> Instead of {{=auth.login()}}, I am using the following to be able to
>> customize my login form. However the resulting form does not work and I
>> cannot login with the same username/password that enable me to login if I
>> had used {{=auth.login()}} -- I get the flash error: Invalid Login.
>>
>> Could someone please tell me what's possibly going wrong? Thanks!
>>
>> {{form=auth.login()}}
>> {{=form.custom.begin}}
>> Username:
>> {{=form.custom.widget.username}}
>> </br>
>> Password:
>> {{=form.custom.widget.password}}
>> {{=form.custom.submit}}
>> {{=form.custom.end}}
>>
>
--