HTML::TurboForm
HTML::TurboForm - fast and compact HTML Form Class
SYNOPSIS
to start with, two simple examples of how to use turboform. I am still working on both the classes and the docs so please be patient.
Usage variant 1 : via objects and methods
my $options;
$options->{ 'label1' }='1';
$options->{ 'label2' }='2';
$options->{ 'label3' }='3';
$form->add_element({ type => 'Html', text =>'<center>' });
$form->add_element({ type => 'Text', name => 'texttest', label => 'element1' } );
$form->add_element({ type => 'Text', name => 'texttest2', label => 'vergleichselement' } );
$form->add_element({ type => 'Textarea', name => 'textareatest', label => 'Areahalt:' } );
$form->add_element({ type => 'Submit', name => 'freeze', label => ' ', value=>'einfrieren' } );
$form->add_element({ type => 'Submit', name => 'unfreeze', label => ' ', value=>'normal' } );
$form->add_element({ type => 'Checkbox', name => 'boxtest', label => 'auswählen', options => $options, params =>{ 'listmode'=>'' } } );
$form->add_element({ type => 'Html', text =>'<hr>' });
$form->add_element({ type => 'Select', name => 'selecttest', label => 'selectieren', options => $options } );
$form->add_element({ type => 'Select', name => 'selecttest2', label => 'selectieren', options => $options, attributes => { 'multiple'=>'' , 'size'=>'3' } } );
$form->add_element({ type => 'Text', name => 'mailtest', label => 'E-Mail' } );
$form->add_element({ type => 'Radio', name => 'tadiotest', label => 'radioteile', options => $options, params =>{ 'listmode', 'norow'} } );
$form->add_element({ type => 'Date', name => 'datetest', label => 'Datum', params=>{ startyear=> '2000' , endyear => '2020' } } );
$form->add_element({ type => 'Image', name => 'imagetest', label => 'Bild', width=>'400', height=>'300',
thumbnail => { width => '60', height=>'80' },
savedir=>'/home/whocares/catalyst/formproject/root/static/images/temp',
loadurl=>'/static/images/temp' } );
$form->add_constraint({ type=> 'Equation', name=> 'texttest', text=> 'kein Vergleich', params=>{ operator => 'eq', comp=>$form->get_value('texttest2') } });
$form->add_constraint({ type=> 'Required', name=> 'boxtest', text=> 'du musst schon was auswählen' });
$form->add_constraint({ type=> 'Date', name=> 'datetest', text=> 'das ist doch kein datum' });
$form->add_constraint({ type=> 'Email', name=> 'mailtest', text=> 'ungültige Mailadresse' });
$form->add_element({ type => 'Html', text =>'</center>' });
$form->freeze_all() if ($form->submitted() eq 'freeze');
$c->stash->{form} = $form->render();
$c->stash->{template}='formtest/formtest.tt';
if ($form->submitted() eq 'freeze') {
my @cols= ('txt1','date','txt2','checkboxtest');
my $data=$form->map_value(@cols);
}
Usage Variant 2 : via yml file:
my $form= new HTML::TurboForm($c->req->params);
$form->load('test.yml');
my $text=$form->render();
if ($form->submitted eq 'freeze') {}
Sample yml-file:
--- languages: - de elements: - type: Html text: <center>
- type: Text
name: messageausyml
label: ausyml
- type: Text
name: txt1
label: sampleinput
- type: Text
name: txt2
label: whatever to compare
- type: Checkbox
label: chooser
name: checkboxtest
options:
label1: 1
label2: 2
- type: Html
text: <div class="form_row"><hr></div>
- type: Radio
label: radiochooser
options:
radio1: 1
radio2: 2
- type: Submit
name: freeze
value: einfrieren
- type: Submit
name: defreeze
value: normal
- type: Date
label: Datum
name: date
params:
startyear: 2000
endyear: 2010
- type: Html
text: </center>
constraints:
- type: Required
name: messageausyml
text: <font size=2><b>mandatory field</b></font>
- type: Date
name: date
text: <font size=2><b>must be a correct date</b></font>
- type: Equation
name: txt1
text: <font size=2><b>must be higher</b></font>
params:
operator: <
compvalue: txt2
DESCRIPTION
HTML::TurboForm was designed as a small, fast and compact Form Class to use with catalyst in order to easily create any needed Form. I know there a quite a lot of classes out there which do the same but i wasn't quite content with what i found. They were either too slow or complicated or both.
METHODS
new
Arguments: $request
Creates new Form Object, needs Request Arguments to fill out Form Elements. To do so it's very important that the form elements have the same names as the request parameters.
add_constraint
Arguments: $params
Adds a new Contraint to the Form. Constraints can be date, required or any other constraint class object. Only if they successfully match the given constraint rule the form will return valid.
load
Arguments: $fn
Loads a form from a given YML File.
unignore_element
Arguments: $name
will unIgnore an element so it will be rendered normally
ignore_element
Arguments: $name
will Ignore an element so it won't be rendered and in effect invisible, it's value will be given to the form as hidden value
add_element
Arguments: $params
Will add a new Form Element, for example a new text element or select box or whatever.
render
Arguments: none
Renders the form. Will retrun the HTML Code for the form including error messages.
submitted
Arguments: none
Will be true if the form is correctly filled out by user, otherwise it returns false and shows the corresponding error message(s).
add_options
Arguments: $name, $option
Adds option to HTML elements that needs them, for example select boxes.
freeze
Arguments: $name
Will disable the HTML Element identified by name for viewing purposes only.
freeze_all
Arguments: none
Freezes the whole form.
unfreeze
Arguments: $name
Unfreezes certain Element.
get_value
Arguments: $name
Returns Value of Eelement by name
populate
Arguments: $data
fills form with values form hash.
map_value
Arguments: @columns
Expects an array with column names. This method is used to map the request and form elements to the columns of a database table.
AUTHOR
Thorsten Drobnik, camelcase@hotmail.com
LICENSE
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 622:
Non-ASCII character seen before =encoding in ''auswählen','. Assuming UTF-8