Table of Contents
Form Handler
- This function is used for form creation in Sahana2. In any module, if a form is required then this can be plugged-in and easily generate various types of forms.
- NB Form validation (which is important) is done separately.
- In order to use form_handler to create forms, there's a certain way of passing values to the function. This document explains the usage of lib_form, step by step:
- Include the function in the script,
include_once ($global['approot']."/inc/lib_form.inc");
Starting a Form
- Use shn_form_fop en to create a form
- Paramaters as follow
- $act : action
- $mod : module name
- $form_opts : Extra Information such as array('enctype'⇒'enctype=“multipart/form-data”') (for upload)
... shn_form_fopen("addmp",null,array('enctype'=>'enctype="multipart/form-data"')); ...
Form Elements
Text Box
- Use shn_form_text to create a text box
... shn_form_text(_('Postal Code'),'zip','size="10"'); ...
Text Area
- Use shn_form_textarea to create a textarea
... shn_form_textarea(_('Address'),"address"); ...
Field Option dropdown (fetch from the field_options table)
- Use shn_form_opt_select to create a field option drop down
... shn_form_opt_select("opt_race",_('Race')); ...
To provide a sorted list of items
... shn_form_opt_select("opt_race",_('Race'),array{'sort' => true}); ...
Upload Element
- Use shn_form_upload to create a upload html element
... shn_form_upload(_('Upload Picture'),"picture"); ...
Submit Button
- Use shn_form_submit to create a submit button
... shn_form_submit(_('Next')); ...
Drop Down
- Use shn_form_select to create a dropdown list
... shn_form_select(array("yes"=>_('Yes'),"no"=>_('No')), 'Have you reported anyone before? ', "reported_before", 'onchange="javascript:toggleLayer(\'toggle_reporter\');"'); ...
Radio Button
- Use shn_form_radio to create a radio button
... shn_form_radio(array('yes'=>'Yes','no'=>'No'), 'Have You reported before ?', "reported_before"); ...
Image Button
... shn_form_image('Test','images/image.jpg',' onclick="js_function1()"); ...
Password Field
- Use shn_form_password to create a password box
... shn_form_password('Enter your Password','passwd'); ...
Field Option multi select (fetch from the field_options table)
- Use shn_form_opt_multi_select to create multi-select field_option
... shn_form_opt_multi_select('opt_status',_('Status')); ...
Field Options Check Boxes
- Use shn_form_opt_checkbox to create check boxes from field options
... shn_form_opt_checkbox('opt_status'); shn_form_checkbox($label, $name, $text_opts = null, $extra_opts = null); ...
- To set a box as already checked set $text_opts = 'checked'
Label (Just to display)
- Use shn_form_label to create a label
... shn_form_label(_('Identity Card Number'),$_SESSION['mpr_add']['entry']['idcard']); ...
Hidden Variables
- Use shn_form_hidden to create a hidden variable
... shn_form_hidden(array('opt_status'=>'mis')); shn_form_hidden(array('key'=>array('val1','val2','val3'); // For Multi Valued Hidden Fields under the same name ...
WYSIWYG Editor (Rich Text Editor)
- Use shn_form_wysiwyg to create a rich text editor
... shn_form_wysiwyg(_t('Description'), 'desc' , array('value'=$html)); ...
Currently this function support FCKeditor and tiny_mce wysiwyg editors. Download and copy any of the editors to www/res directory and change configuration option $conf['wysiwyg'] to editor you are using.
Secure Hyperlink (Only in exp_acl1 branch currently)
Currently this function is only available in the exp_acl1 branch and other branches that use the new ACL system.
... shn_acl_secure_hyperlink('mod','action',_t('Link Tex'),$stream=null,$params=array(),$text_opts=''); ... shn_acl_secure_hyperlink('module','action','Link Text','stream (html by default)',array('parameter1'=>'v1','parameter2'=>'v2','parameter3'=>'v3'),'text options for the tag') ...
Highlight Empty Required Fields
- Used to indicate the user that required field(s), such as Full Name, Group Head, etc is/are left there to be filled in the form. During the validation process, if the 'has_error' is set to 'true' of the fields marked as required will get highlighted on the form along with the warning message.
... shn_form_text(_t('Full Name'), 'full_name', 'size="10"', array('req'=>'true', 'has_error'=>'true')); shn_form_textarea(_t('Description'), 'description', array('req'=>'true', 'has_error'=>'true')); ...
Creating Sections
Start a section
- Use shn_form_fsopen to create a new section
... shn_form_fsopen(_('Identity')); ...
End a section
- Use shn_form_fsclose to close a section
... shn_form_fsclose(); ...
Closing the Form
- Use shn_form_fclose to close a form
... shn_form_fclose(); ...