Ejemplo n.º 1
0
 /**
  * FormHandler::selectField()
  *
  * Create a selectField on the form
  *
  * @param string $title: The title of the field
  * @param string $name: The name of the field
  * @param array $options: The options used for the field
  * @param string $validator: The validator which should be used to validate the value of the field
  * @param boolean $useArrayKeyAsValue: If the array key's are the values for the options in the field
  * @param boolean $multiple: Should it be possible to select multiple options ? (Default: false)
  * @param int $size: The size of the field (how many options are displayed)
  * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  * @return void
  * @access public
  * @author Teye Heimans
  */
 function selectField($title, $name, $options, $validator = null, $useArrayKeyAsValue = null, $multiple = null, $size = null, $extra = null)
 {
     require_once FH_INCLUDE_DIR . 'fields/class.SelectField.php';
     // options has to be an array
     if (!is_array($options)) {
         trigger_error("You have to give an array as value with the selectfield '{$name}'", E_USER_WARNING);
         return;
     }
     // create new selectfield
     $fld = new SelectField($this, $name);
     $fld->setOptions($options);
     if (!empty($validator)) {
         $fld->setValidator($validator);
     }
     if (!is_null($useArrayKeyAsValue)) {
         $fld->useArrayKeyAsValue($useArrayKeyAsValue);
     }
     if (!empty($extra)) {
         $fld->setExtra($extra);
     }
     if ($multiple) {
         $fld->setMultiple($multiple);
     }
     // if the size is given
     if (!empty($size)) {
         $fld->setSize($size);
     } else {
         if ($multiple) {
             $fld->setSize(4);
         }
     }
     // register the field
     $this->_registerField($name, $fld, $title);
 }