Sahana libraries’ limitation of a common interface
In an attempt to make a reusable component for form handling in Logistics, that supports validation and performs form processing automatically, I went through a few difficulties that are prevailing in the current libraries.
The form library does not use a common interface,
eg. lib_form.inc
function shn_form_button($name, $button_opts = null, $extra_opts = null)
function shn_form_text($label, $name, $text_opts = null, $extra_opts = null )
function shn_form_hidden($hidden_vars)
function shn_form_checkbox($label, $name, $text_opts = null, $extra_opts = null)
function shn_form_select($options,$label, $name,$select_opts = “”, $extra_opts = null)
function shn_form_radio($options, $label, $name, $select_opts = “”, $extra_opts = null)
function shn_form_radio2($options, $label, $name, $checked, $extra_opts = null)
function shn_form_multi_select($name,$options, $label, $select_opts = “”, $extra_opts = null)
function shn_form_opt_checkbox($opt_field,$extra_opts=null)
function shn_form_textarea($label, $name, $text_opts=null, $extra_opts = null)
function shn_form_upload($label, $name, $extra_opts = null)
function shn_form_label($label, $caption, $extra_opts = null)
function shn_form_password($label, $name, $text_opts = null, $extra_opts = null)
function shn_form_date($label, $name, $extra_opts=null)
The function signatures are different in even the same kind of form elements. Since the form elements do not have a common interface, it is hard to use these functions in a generalized way.
I feel that a better approach would be something like in the Zend Framework. The form elements in Zend framework are as below.
class Zend_Form_Element_Button extends Zend_Form_Element_Submit
class Zend_Form_Element_Reset extends Zend_Form_Element_Submitclass Zend_Form_Element_Checkbox extends Zend_Form_Element_Xhtml
class Zend_Form_Element_Captcha extends Zend_Form_Element_Xhtml
class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
class Zend_Form_Element_Hash extends Zend_Form_Element_Xhtml
class Zend_Form_Element_Hidden extends Zend_Form_Element_Xhtml
class Zend_Form_Element_Image extends Zend_Form_Element_Xhtml
class Zend_Form_Element_Text extends Zend_Form_Element_Xhtml
class Zend_Form_Element_Textarea extends Zend_Form_Element_Xhtml
class Zend_Form_Element_Password extends Zend_Form_Element_Xhtmlclass Zend_Form_Element_Multiselect extends Zend_Form_Element_Select
class Zend_Form_Element_Select extends Zend_Form_Element_Multiclass Zend_Form_Element_Radio extends Zend_Form_Element_Multi
class Zend_Form_Element_MultiCheckbox extends Zend_Form_Element_Multiclass Zend_Form_Element_Submit extends Zend_Form_Element_Xhtml
abstract class Zend_Form_Element_Multi extends Zend_Form_Element_Xhtml
abstract class Zend_Form_Element_Xhtml extends Zend_Form_Element
They all inherit from the same type, therefore having a common interface.
Zend is a Object Oriented framework whereas Sahana is procedural, therefore it might be hard to enforce the use of a common interface for the same kind of elements in Sahana libraries


