Multiple fields in web2py FORM
I want to make a simple FORM (not SQLFORM) in web2py with two fields namely 'name' and 'password'. I have used the following code
form=FORM('Cloned VM Name:',INPUT(_name='name',requires=IS_NOT_EMPTY()开发者_运维知识库),
'VNC Password:',INPUT(_name='password',_type='password',requires=IS_NOT_EMPTY()),
INPUT(_type='submit', _value='Clone it!'))
I could generate the form but the fields are not appearing what we expect it like
Is there a way i can position the fields.
The FORM and INPUT helpers are just replacements for the HTML <form>
and <input>
tags, so your code will produce this HTML:
<form action="" enctype="multipart/form-data" method="post">
Cloned VM Name:<input name="name" type="text" />
VNC Password:<input name="password" type="password" />
<input type="submit" value="Clone it!" />
</form>
Depending on how you want the form formatted, you could add additional web2py HTML helpers and/or use CSS. For example, if you want each input on a separate line, just put each one into a DIV:
form=FORM(DIV('Cloned VM Name:',INPUT(_name='name',requires=IS_NOT_EMPTY())),
DIV('VNC Password:',
INPUT(_name='password',_type='password',requires=IS_NOT_EMPTY())),
DIV(INPUT(_type='submit',_value='Clone it!')))
Alternatively, if you want to take advantage of some of web2py's SQLFORM functionality (such as the formstyle
argument to control the formatting) but do not want to base the form on a database table, you can use SQLFORM.factory.
精彩评论