As I needed to build my own submit buttons, or add my own widgets, I use 
the following function to split a SQLFORM:
import re

def expurgate_form(web2py_form):
    '''
    Deletes surrounding <form> tag, and submit row.
    '''
    regexp_opening_tag = re.compile("^<[^><]*>")
    regexp_closing_tag = re.compile("<[^><]*>$")
    form_xml = web2py_form.xml()
    opening_tag = regexp_opening_tag.search(form_xml).group()
    closing_tag = regexp_closing_tag.search(form_xml).group()
    realform=TAG(form_xml)
    table = realform.elements('table')[0]
    hidden_elements = realform.elements("input[type=hidden]")
    hidden_element = DIV(*hidden_elements)
    hidden_element['_style'] = "display:none;"
    todelete = table.elements("input[type=submit]")
    submit = todelete[0]
    todelete[0].parent[0]=''
    return (table,hidden_element,XML(opening_tag),XML(closing_tag),submit)


To use it in a view:
{{(table,hidden_element,opening_tag,closing_tag,submit)=expurgate_form(form
)}}
{{=opening_tag}}
{{#<!-- Add header here -->}}
{{=table}}
{{#<!-- Add footer here -->}}
 {{=hidden_element}}
{{#<!-- Add submit/cancel buttons here - you may even not use the submit 
variable -->}}
 {{=submit}}
 {{=closing_tag}}


I hope it will help :-)


Le vendredi 4 mai 2012 08:30:23 UTC+2, Annet a écrit :
>
> I'd like to divide the default/user.html forms into a body and footer 
> part, the body containing the fields the footer containing the cancel and 
> submit button, something like this:
>
> <div class="form">
>   <div class="form-header">
>     <h3>Login with your Leonexus ID</h3>
>   </div> <!-- /form-header -->
>   <div class="form-body">
>       <h5>Enter your username and password</h5>
>
>       the form fields here
>
>   </div> <!-- /form-body -->
>   <div class="form-footer">
>
>       the form controls here
>
>   </div> <!-- /form-footer -->
>  </div> <!-- /form -->
>
> Is there a way to split the form in these components?
>
>
> Kind regards,
>
> Annet
>

Reply via email to