A simple modul snipplet for a class for
formulars forms
Once you have the modul installed you can use a class "cForm" to build forms.
Notice: this is not QuickForm (PEAR) and it is not mean as a portation to WebsiteBaker at all;
even no recoding of the package.
Current Version: 0.1.3.beta - 2008-10-07
update: multiple selections support
Requirements:
- WebsiteBaker 2.7
- PHP 5.2.x
Known issues
- No options/radio - groups
- No validations
- No file-upload
ToDo - Roadmap
- add options/radio - groups
- add simple client/serverside validations
- file-upload
Bugfix in 0.1.2 Alpha: Checkbox-bugfix for missplaced "'" single quote ...
Bugfix in 0.1.1 Alpha: Typos ("cancle" instead of "cancel")
Any kind of improvment, critics, recomentations, code-cleanings, warnings and grumble
are always wellcome.
Some examples:
If you want to use this class in the backend you are in the need to import it first, like
<?php
require_once (WB_PATH.'/modules/x_cform/include.php');
?>
If you want to use it inside a template you don't need it.
Initial within some formattributes, you can use any valid attribute as you like inside an assoc. array.<?php
$form_attribs = Array (
'name' => "wb_addresses_form",
'class' => "xForm",
'action' => $_SERVER['PHP_SELF']
);
$form = new c_form( $form_attribs );
?>
Add a hidden field with the name "id" and a typical value to the formular<?php
$form->addElement( Array ('type' => 'hidden', 'name' => "id", "value" => $_REQUEST['id']) );
?>
Add a textfield with an label to the formular<?php
$form->addElement( Array ('type' => 'text', 'label'=> ucfirst($i), 'name' => $i, 'value' => $data[$i] ) );
?>
Add a textarea to the formular<?php
$form->addElement( Array ('type' => 'textarea', 'label'=> ucfirst($i), 'name' => $i, 'content' => $data[$i] ) );
?>
Add a select to the formularAs a "content" you will have to pass an assoc. array in the form "Key" = value, where the Key is display
in the popup menu. You can also pass a "select"-value to the select.
<?php
$content = array (
'Anna' => 1,
'Judith' => 2,
'Mary Lou' => 3,
'Xanthippe' => 4
}
$form->addElement( Array ('type' => 'select', 'label' => ucfirst($i), 'name' => $i, 'content' => $group_select, 'select'=>3 ) );
?>
Add a submit-button within some javascript.<?php
$form->addElement ( Array ('type' => 'submit', 'name' => 'submit', 'value' => $TEXT['SAVE'], 'onclick' => "this.submit();") );
?>
update 0.1.3: support for multiple select ...
<?php
$form->addElement ( Array (
'type' => 'select',
'name' => "group_id[]",
'label' => $ADDRESSES['DISPLAYGROUP'],
'content' => $group_select,
'select' => explode(",",$temp_data['groups']), // !
'multiple' =>'multiple',
'size' => 4,
'onload' => "alert(this);"
) );
?>
echo the complete form out of a module or template<?php
echo $form->toHTML();
?>
Also supported types are "html", for "pur" html-code, "button", "cancel" and "checkbox".
To modify the output you can manipulate/change the template-strings (all public):
- $form_template - holds the complete form, default is:
"\n<form {{ attribs }}>\n{{ hidden }}\n<table>\n{{ content }}</table>\n</form>\n";
within the markers for
- {{ attribs }} :: the formular-attributes, e.g. name, class, onchange, onsubmit, action, method ...
- {{ hidden }} :: where to place the hidden values; by default at the begin of the formular
- {{ content }} :: the complete formular-content
- $element_template - holds a single element, default is:
"<tr>\n\t<td class='left'>{{ label }}</td>\n\t<td class='right'>{{ content }}</td>\n</tr>\n"
within the markers for
- {{ label }} :: where to display the label of the element
- {{ content }} :: where to display the element
So if you want to display the formular-elements inside divs you can easy overwrite the templates as you needed.
Regards
Aldus
[gelöscht durch Administrator]