This is an old revision of the document!


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
    1. $act : action
    2. $mod : module name
    3. $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

...
    shn_form_text(_('Postal Code'),'zip','size="10"');
...

Text Area

...
    shn_form_textarea(_('Address'),"address");
...

Field Option dropdown (fetch from the field_options table)

...
    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

...
     shn_form_upload(_('Upload Picture'),"picture");   
...

Submit Button

...
    shn_form_submit(_('Next'));
...
...
    shn_form_select(array("yes"=>_('Yes'),"no"=>_('No')),
            'Have you reported anyone before? ',
            "reported_before",
            'onchange="javascript:toggleLayer(\'toggle_reporter\');"');
...

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

...
    shn_form_password('Enter your Password','passwd');
...

Field Option multi select (fetch from the field_options table)

...
    shn_form_opt_multi_select('opt_status',_('Status'));
...

Field Options Check Boxes

...
    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)

...
    shn_form_label(_('Identity Card Number'),$_SESSION['mpr_add']['entry']['idcard']);
...

Hidden Variables

...
    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)

...
    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.

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

...
   shn_form_fsopen(_('Identity')); 
...

End a section

...
    shn_form_fsclose();
...

Closing the Form

...
    shn_form_fclose();
...

Navigation
QR Code
QR Code dev:form_handler (generated for current page)