HTML::Field

Generation of HTML form elements
Download

HTML::Field Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Julio Fraire Domínguez
  • Publisher web site:
  • http://search.cpan.org/~jfraire/

HTML::Field Tags


HTML::Field Description

Generation of HTML form elements HTML::Field objects are able to read their values from CGI objects, hash references or plain scalars and then render those values as HTML fields or simple read-only HTML. They are meant to ease the interface between CGI, databases and templates.IMPORTANT NOTE: HTML::Field is a Perl module that does not validate the values of any HTML attributes that you supply.See HTML::FieldForm for a class that works on sets of HTML::Fields.SYNOPSIS use HTML::Field; ########## Creation of Field objects ############## # A text field: my $field1 = HTML::Field->new('Textfield', name => 'fieldname', value => 'current value', default => 'default value', size => 15, maxlength => 15 ); # A Pasword field (has the same attributes as 'Textfield'): my $field2 = HTML::Field->new('Passwd', name => 'fieldname', value => 'current value', default => 'default value', size => 15, maxlength => 15 ); # A hidden field: my $hidden = HTML::Field->new('Hidden', name => 'sid', value => 'cgiasf25k', default => undef ); # A text area: my $area = HTML::Field->new('Textarea', name => 'address', cols => 40, rows => 4 ); # A 'select' tag. Options are given in an array reference; labels are # given in a hash keyed by the options: my $select = HTML::Field->new('Select', name => 'select_color', options => , default => 'red', labels => {red => 'Color of apples', yellow => 'Color of mangos!', brown => 'Color of chocolate'}, multiple => undef, # Multiple is either true or false size => 1 ); # Size of select box # A radio button. Note that it will generate the HTML for all of its # options, and those will be named as 'name_option' my $radio_buttons = HTML::Field->new('Radio', name => 'Flavors', options => , default => 'Grapefruit' ); # A single checkbox: my $checkbox = HTML::Field->new('Checkbox', name => 'Additional', option => 'Strawberry', default => 1, read_only_tags => { true => 'X', false => 'o'}); # Render editable HTML my ($key, $value) = $field->editable_html; # Render read-only value ($key, $value) = $field->readonly_html; # Render editable HTML for a new element ($key, $value) = $field->creation_html; # Set a field's value from a CGI object, hash reference or scalar: my $value = $field->value($cgi); # or, get the filed's value: $value = $field->value; # The 'read_only_tags' attribute sets the representation of a # check box or of radio buttons for a 'read only' rendering. # This feature can be used to load different images to represent # 'checked' radio buttons or check boxes. # Primary Key text field: my $field1 = HTML::Field->new('Textfield', name => 'login', size => 15, maxlength => 15, primary_key => 1 ); # When a text field is marked as 'primary' key, then # it will not be editable once it has a value. This means that if you # are displaying an empty form this will be an editable text field, # but if you are displaying a database record for edition, then this # field will not be editable and it will also be present as a hidden # field in order to get sent back to the script. # Primary key autogenerated by the database: my $serial = HTML::Field->new('Textfield', name => 'company_id', size => 4, maxlength => 4, auto => 1 ); # The same as above applies if the field value is generated by the # database. In that case, the value will never be editable; if the # field has no value then a place holder will be returned instead. Requirements: · Perl


HTML::Field Related Software