NAME

Form::Sensible::Renderer::HTML::RenderedForm - A rendered form handle for HTML

SYNOPSIS

use Form::Sensible::Renderer::HTML;

my $renderer = Form::Sensible::Renderer::HTML->new();

my $renderedform = $renderer->render($form);

print $renderedform->complete('/myform/submit', 'POST');

DESCRIPTION

The Form::Sensible::Renderer::HTML::RenderedForm class defines the result of rendering a form as HTML. It is not generally created directly, but rather is created by passing a form to the Form::Sensible::Renderer::HTML render() mathod.

ATTRIBUTES

stash

The stash used for the template processing. Additional information is added to this stash automatically during field and form processing.

css_prefix

This is applied to all html element CSS id's and class names. By default, css_prefix is set to fs_

render_hints

Render hints provide information on how to render certain aspects of the form or field. The usage depends upon the field type in question. The information is passed through to the field-specific templates as 'render_hints' during processing.

A hint that is specific to the HTML renderer is stash_vars, this should be a hash and will be passed to the templates as they are rendered.

{
    stash_vars => {
        user_prefs => $user_prefs
    }
}

For example in the this case, $user_prefs could be accessed in any of the templates (form_start.tt, text.tt etc) as [% user_prefs %].

Another is field_wrapper which should be the name of a template to act as a wrapper for each individual field template. This can be useful if each field has common HTML and only the actual field element changes. For example in this case:

{
    field_wrapper => 'field_wrapper_file'
}

A template called field_wrapper_file.tt will be used. The field_wrapper hint overrides the built-in wrapper, so only the actual input field will be available and you will need to provide any enclosing elements or labels. Note also that it uses the standard Template WRAPPER mechanism. Thus the field wrapper template will be rendered, and the actual input elements will be available as [% content %] within your wrapper template. So your wrapper template might end up looking like:

<tr class="form-row">
  <td>[% field.display_name %]</td>
  <td>[% content %]</td>
</tr>

For more information on render_hints, see Form::Sensible::Overview.

Note that 'wrap_fields_with' has been deprecated and will be removed in a future release.

status_messages

An array ref containing the status messages to be displayed on the form.

error_messages

An array ref containing the error messages to be displayed on the form.

form_template_prefix

Non-field related template names are prefixed with this value. The three templates used for each form are: start, messages, and end, The default value for form_template_prefix is 'form', so by default the form templates used are: form_start.tt, form_messages.tt, and form_end.tt.

subform_renderers has

This contains the references to subform renderers. Subform rendering is experimental and is still subject to changes. It's probably best to leave this attribute alone for now.

form

A reference to the form object that is being rendered.

template

The template toolkit object to be used to process the templates. This is normally set up prior to rendering and should only be changed if you know what you are doing. In other words, unless you've read the source, it's a good idea to leave this alone.

template_fallback_order

An array ref containing the order to seek for overriding templates for all elements of form rendering. By default, a subdirectory named after the $form->name is searched first, then the root template directory is searched.

METHODS

add_status_message($message)

Adds $message to the status messages to be displayed.

add_error_message($fieldname, $message)

Adds the error message provided in $message to the list of error messages to be displayed. The error message is associated with the $fieldname given.

add_errors_from_validator_result($validator_result)

Inspects $validator_result and adds any messages found to the list of errors to be displayed on the form.

start($action, $method)

This renders the start of the form and sets it to be submitted to the url provided in $action. $action is placed directly in to the action attribute of the form element. Returns the rendered HTML as a string.

messages()

This renders the messages portion of the form. Often (and by default) this is displayed before the form fields. Returns the rendered messages html as a string.

render_field($fieldname, $render_hints)

Renders the field matching $fieldname and returns the rendered HTML for the field. If the $render_hints hashref is provided, it will be merged into any previously set render hints for the field. When a key conflict occurs the passed $render_hints will override any existing configuration.

fields($manual_hints)

A shortcut routine that renders all the fields in the form. Returns all of the fields rendered as a single string.

end sub

Renders the end of the form. Returns the rendered html as a string.

fieldnames()

Returns an array containing the fieldnames in the form (in their render order)

complete($action, $method, $manual_hints)

Renders the entire form and returns the rendered results. Calling <$form-complete($action, $method) >> routine is functionally equivalent to calling:

$form->start($action, $method) . $form->messages() . $form->fields() . $form->end();

DELEGATE CONNECTIONS

display_name_delegate: ($caller, $display_name, $field_or_form_object)

The display_name_delegate provides a hook to allow for localization of form and field names. It is passed the field or form name as well as the field or form object and is expected to return the translated name. It is important to return a value. If you are unable to translate the name, returning the passed name unchanged is encouraged.

AUTHOR

Jay Kuri - <jayk@cpan.org>

SPONSORED BY

Ionzero LLC. http://ionzero.com/

SEE ALSO

Form::Sensible

LICENSE

Copyright 2009 by Jay Kuri <jayk@cpan.org>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.