HOWTO: crear formularios FORM identicos a determinado HTML

position – Multiple fields in web2py FORM – Stack Overflow

 

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
enter image description here

Is there a way i can position the fields.

link|improve this question


 
   
feedback

1 Answer

up vote
1
down vote
accepted

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.

link|improve this answer
0

0
 

HOWTO: Especificar un subconjunto con IS_IN_DB (db(condition), ‘.id’, ‘%(name)s’)

python – web2py, Database relationships and permissions – Stack Overflow

 

So i’ve this problem i’ve 2 tables for example templates(id,user_id,template_name,reference) user_settings(id,user_id,default_template)

so each user can create many templates and in his settings he can choose a default template that he will always use

so now there is many users so when a user want to choose a default template, he can see all templates (his own templates and the templates for the other users)

tables are so defined:

db.define_table('i2l_templates',
    Field('id','id',
          represent=lambda id:SPAN(A('view',_href=URL('view_template',args=id)),' | ',
                                          A('edit',_href=URL('edit_template',args=id)))),
    Field('user_id', db.auth_user, default=auth.user_id, writable=False,readable=False,
          label=T('User Id')),
    Field('template_name', requires=IS_NOT_EMPTY(), type='string',
          label=T('Template name')),
...
...
...
)

db.define_table('user_settings',
    Field('id','id',
          represent=lambda id:SPAN(A('view',_href=URL('view_settings',args=id)))),
    Field('user_id', db.auth_user, default=auth.user_id, writable=False,readable=False,
          label=T('User Id')),
    Field('standard_template_id', templates,
          label=T('Standard Template')),
...
...
)

what should i do to make user choose only his own template!

link|improve this question
 
   
feedback