[%# Shows a user input form, usually for adding a single row to a single table. Parameters: self - the site object (if self has a params hash values shown on the form are taken from it) view.title - thr browser window title view.form - a hash with these keys: method - POST or GET (defaults to POST) action - url of page to process form (defaults to self.uri) name - the name of the form (useful for javascript references) row - the current row object from the table (if available) javascript - javascript code the form needs (like for date popups. Consider using Gantry::Plugins::Calendar and calling its calendar_month_js. (This could actually be anything, it just gets copied to the output immediately after the form opening tag) legend - The title for the legend box wrapping the form. change_log - An array of change_log entries (optional). Each entry is a hash with these keys: date - the date the change happened by - the name of the person making the change message - what happened results - the return value from Data::FormValidator->check cellspacing - becomes the cellspacing parameter of the form's table (defaults to 0) width - becomes the width parameter of the form's table fields - an array of inputable items. Each element is a has with these keys: raw_html - copied to the table before the row for the field label - text description displayed to user content - additional description text used only next to the input box, not in errors. width - width of the field's label_width - width of the field's label name - the name of the field in the form (much match the database column name) default_value - what shows up if there is no previous value and nothting is in the database type - One of: select (pick one drop down list) select_multiple (pick 1 or more) text textarea the rest of the keys in the fields hash depend on the type: select options - An array of hashes with these keys: value - the form's value for this option label - what the user sees in the list select_multiple options - just as for select selected - a code reference which accepts one value, and the form params. Return true if the value is selected, false otherwise. Usually Gantry::Plugins::CRUD's select_multiple_closure works well. text date_select_text - the text of the href link for the date popup window. You must include this to get a date popup link. display_size - the size attribute of the input element (this is called display_size because TT has a pseudo-method .size which tells how many keys are in the field's hash) textarea rows - how tall the area is cols - how wide the area is checkbox checked - true if you want initial check mark display foreign - use foreign_display to get the text Default values are taken in the following order: 1. from the params hash (which was made in a previous failed add/edit attempt) 2. from the data model row object (on first edit attempt) 3. from the default_value entry in the field's hash (if available) If none of those work, text and textarea fields will be blank and select lists will rest on the first item in the options list. %] [% title = view.title %] [% IF view.form.editor == 1 %] [% INCLUDE "editor_init.ttc" %] [% END %] [% IF view.form.description %]
[% view.form.description %]
[% END %]
[% view.form.javascript %]
[% view.form.legend %] [%- IF view.form.change_log %]
Change Log
[% FOREACH entry IN view.form.change_log %] [% entry.date %] By [% entry.by %]
· [% entry.message %]
[% END %]
[%- END %] [% IF view.form.error_text %]
Error: [% view.form.error_text %]

[% END %] [% IF view.form.results.missing %]
Missing: [% missing_names = [] %] [% FOREACH field IN view.form.fields %] [% IF view.form.results.missing( "${field.name}" ) %] [% missing_names.push( field.label ) %] [% END %] [% END %] [% missing_names.join( ', ' ) %]

[% END %] [% IF view.form.results.invalid %]
Invalid: [% invalid_names = [] %] [% FOREACH field IN view.form.fields %] [% IF view.form.results.invalid( "${field.name}" ) %] [% invalid_names.push( field.label ) %] [% END %] [% END %] [% invalid_names.join( ', ' ) %]

[% END %]
[%- FOREACH field IN view.form.fields -%] [%- IF field.raw_html %] [%- field.raw_html %] [%- END %] [%- IF field.type == 'hidden' %] [%- NEXT %] [%- END %] [%- IF view.form.results.missing( "${field.name}" ) OR view.form.results.invalid( "${field.name}" ) %] [% style_str = ' style="color: red"' %] [%- ELSE %] [% style_str = '' %] [%- END %] [%- END %]
[%- field.label %] [%- IF field.content %] [% field.content %][% END %] [%- UNLESS field.optional or field.type == 'checkbox' or field.type == 'display' -%]*[% END %] [%- IF field.type == 'select' %] [%- IF field.onchange -%] [%- END %] [%-# clear field_val_hash for each loop %] [%- field_val_hash = {} -%] [%- FOR option IN field.options -%] [%- IF view.form.row.defined %] [% row_value = view.form.row.${field.name} %] [%- END -%] [%- IF ( option.value == self.params.${field.name} && self.params.defined("${field.name}") ) %] [%- field_val_hash.param_field = option.value %] [%- ELSIF option.value == row_value %] [%- field_val_hash.database_field = option.value %] [%- ELSIF option.value == field.default_value %] [%- field_val_hash.default_field = option.value %] [%- END %] [%- END -%] [%- IF field_val_hash.defined('param_field'); selected_value = field_val_hash.param_field; ELSIF field_val_hash.defined('database_field'); selected_value = field_val_hash.database_field; ELSE; selected_value = field_val_hash.default_field; END; -%] [%- FOR option IN field.options %] [%- END %] [%- ELSIF field.type == 'select_multiple' %] [%- ELSIF field.type == 'textarea' %] [%- IF self.params.${field.name}.defined; input_value = self.params.${field.name}; ELSIF view.form.row.${field.name}.defined; input_value = view.form.row.${field.name}; ELSE; input_value = field.default_value; END; -%] [%- ELSIF field.type == 'checkbox' %] [%- ELSIF field.type == 'html' -%] [% field.text || field.html %] [%- ELSIF field.type == 'display' -%] [% IF field.foreign %] [% view.form.row.${field.name}.foreign_display %] [% ELSE %] [% view.form.row.${field.name} %] [% END %] [%- ELSIF field.type == 'date' -%] [%- IF self.params.${field.name}.defined; input_value = self.params.${field.name}; ELSIF view.form.row.${field.name}.defined; input_value = view.form.row.${field.name}; ELSE; input_value = field.default_value; END; -%]
[%- ELSE -%] [%- IF self.params.${field.name}.defined; input_value = self.params.${field.name}; ELSIF view.form.row.${field.name}.defined; input_value = view.form.row.${field.name}; ELSE; input_value = field.default_value; END; -%] [%- IF field.date_select_text -%] [% popup = "datepopup('$field.name')" %] [% field.date_select_text %] [%- END %] [%- END %]
[% field.hint ? field.hint : '' %]
* required field
[% IF view.form.submit_and_add_another %] [% END %] [% UNLESS view.form.no_cancel %] [% END %]