form_tag

Form Tag Helpers


Functions

f form(url, method='POST', multipart=False, **options) ...

Starts a form tag that points the action to an url.

The url options should be given either as a string, or as a url() function. The method for the form defaults to POST.

Options:

multipart
If set to True, the enctype is set to "multipart/form-data".
method
The method to use when submitting the form, usually either "GET" or "POST". If "PUT", "DELETE", or another verb is used, a hidden input with name _method is added to simulate the verb over POST.

f start_form(url, method='POST', multipart=False, **options) ...

Starts a form tag that points the action to an url.

The url options should be given either as a string, or as a url() function. The method for the form defaults to POST.

Options:

multipart
If set to True, the enctype is set to "multipart/form-data".
method
The method to use when submitting the form, usually either "GET" or "POST". If "PUT", "DELETE", or another verb is used, a hidden input with name _method is added to simulate the verb over POST.

f end_form() ...

Outputs "</form>"

Example:

>>> end_form()
'</form>'

f select(name, option_tags='', **options) ...

Creates a dropdown selection box

option_tags is a string containing the option tags for the select box:

>>> select("people", "<option>George</option>")
'<select id="people" name="people"><option>George</option></select>'

Options:

f text_field(name, value=None, **options) ...

Creates a standard text field.

value is a string, the content of the text field

Options:

Remaining keyword options will be standard HTML options for the tag.

f hidden_field(name, value=None, **options) ...

Creates a hidden field.

Takes the same options as text_field

f file_field(name, value=None, **options) ...

Creates a file upload field.

If you are using file uploads then you will also need to set the multipart option for the form.

Example:

>>> file_field('myfile')
'<input id="myfile" name="myfile" type="file" />'

f password_field(name='password', value=None, **options) ...

Creates a password field

Takes the same options as text_field

f text_area(name, content='', **options) ...

Creates a text input area.

Options:

Example:

>>> text_area("body", '', size="25x10")
'<textarea cols="25" id="body" name="body" rows="10"></textarea>'

f check_box(name, value='1', checked=False, **options) ...

Creates a check box.

f radio_button(name, value, checked=False, **options) ...

Creates a radio button.

The id of the radio button will be set to the name + value with a _ in between to ensure its uniqueness.

f submit(value='Save changes', name='commit', confirm=None, disable_with=None, **options) ...

Creates a submit button with the text value as the caption.

Options:

See the source for more information.