Tuesday, February 06, 2007

Form helper methods

form(url) ...

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".

start_form(url)

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".

end_form()

Outputs ""

select(name, option_tags='')

Creates a dropdown selection box

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

>>> select("people", "George")

Options:

  • multiple - If set to true the selection will allow multiple choices.

text_field(name, value=None)

Creates a standard text field.

value is a string that will the contents of the text field will be set to

Options:

  • disabled - If set to True, the user will not be able to use this input.
  • size - The number of visible characters that will fit in the input.
  • maxlength - The maximum number of characters that the browser will allow the user to enter.

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

hidden_field(name, value=None)

Creates a hidden field

Takes the same options as text_field

file_field(name, value=None)

Creates a file upload field.

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

password_field(name='password', value=None)

Creates a password field

Takes the same options as text_field

text_area(name, content='')

Creates a text input area.

Options:

  • size - A string specifying the dimensions of the textarea.

Example:

>>> text_area("body", '', size="25x10")

check_box(name, value='1', checked=False)

Creates a check box.

radio_button(name, value, checked=False)

Creates a radio button.

submit(value='Save changes', name='commit')

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

Options:

  • confirm - A confirm message displayed when the button is clicked.
  • disable_with - The value to be used to rename a disabled version of the submit button.

If options contains a keyword pair with the key of "disable_with", then the value will be used to rename a disabled version of the submit button.

0 comments: