2011/1/27 David J. <da...@styleflare.com>

> I asked before "what is the easiest way to add a non-database field to the
> registration form"
>
>
> Right now I dont see an easy way to do this;
>

You can interact with the HTML for the FORM object.

form = auth()
form.elements[0].append(SOME_OTHER_ELEMENT)

The FORM is rendered as HTML by the web2py template system, it happens just
when it is passed to response.write (which is similar to print statement)

If you try

in controllers/default.py
def myauth(): return dict(form=auth())

then in view you do:

{{=dir(response._vars['form'])}}
{{=type(response._vars['form'])}}

You get:
*DIR*
['FIELDKEY_DELETE_RECORD', 'FIELDNAME_REQUEST_DELETE', 'ID_LABEL_SUFFIX',
'ID_ROW_SUFFIX', '__class__', '__delattr__', '__delitem__', '__dict__',
'__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__',
'__init__', '__len__', '__module__', '__new__', '__nonzero__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__',
'__str__', '__subclasshook__', '__weakref__', '_fixup', '_postprocessing',
'_setnode', '_traverse', '_validate', '_wrap_components', '_xml', 'accepts',
'append', 'attributes', 'components', 'custom', 'element', 'elements',
'errors', 'factory', 'field_parent', 'fields', 'flatten', 'formkey',
'formname', 'formstyle', 'hidden_fields', 'ignore_rw', 'insert',
'keepvalues', 'latest', 'parent', 'record', 'record_changed', 'record_id',
'regex_attr', 'regex_class', 'regex_id', 'regex_tag', 'request_vars',
'session', 'sibling', 'siblings', 'table', 'tag', 'update', 'vars',
'widgets', 'xml']

*TYPE*
<class 'gluon.sqlhtml.SQLFORM'>

If you try

{{=form}} which is the same as {{respose.write(form)}} then you get the
object rendered as HTML.

Until this point you have only a object types as <class
'gluon.sqlhtml.SQLFORM'>

*Manipulation of the SQLFORM object*

{{=form.elements()[0].insert(0,LABEL('test:',INPUT(_type='text')))}}

or in a more comprehensive way

{{=form.elements('form tr td')[0].insert(0,INPUT())}}

But, I think it is possible to catch that *class* object and perform some
kind of redraw method before the html rendering.

Reply via email to