Beispiel #1
0
 /**
  * Create a new field
  * 
  * @access public
  * @param mixed $alias
  * @param mixed $driver. (default: NULL)
  * @param mixed array $options. (default: NULL)
  * @return void
  */
 public function __construct($alias, $driver = NULL, $value = NULL, array $options = NULL)
 {
     $options = func_get_args();
     $orig_options = $options;
     $options = Formo::args(__CLASS__, __FUNCTION__, $options);
     // Add all the options to the object
     $this->load_options($options);
     // Run the driver's post_construct() method
     $this->driver()->post_construct();
 }
Beispiel #2
0
 /**
  * Create a new field
  *
  * @access public
  * @param mixed $alias
  * @param mixed $driver. (default: NULL)
  * @param mixed array $options. (default: NULL)
  * @return void
  */
 public function __construct($alias, $driver = NULL, $value = NULL, array $options = NULL)
 {
     $options = func_get_args();
     $orig_options = $options;
     $options = Formo::args(__CLASS__, __FUNCTION__, $options);
     // Always process the driver first
     $driver = $options['driver'];
     unset($options['driver']);
     $options = Arr::merge(array('driver' => $driver), $options);
     // Add all the options to the object
     $this->_load_options($options);
     // Run the driver's post_construct() method
     $this->driver()->post_construct();
 }
Beispiel #3
0
 /**
  * Adds a field to a form
  *
  * @access public
  * @param mixed $alias
  * @param mixed $driver. (default: NULL)
  * @param mixed $value. (default: NULL)
  * @param mixed array $options. (default: NULL)
  * @return object
  */
 public function add($alias, $driver = NULL, $value = NULL, array $options = NULL)
 {
     // If Formo instnace was passed
     if ($alias instanceof Formo_Form) {
         return $this->add_object($alias);
     }
     if ($driver instanceof Formo_Form) {
         return $this->add_object($driver->alias($alias));
     }
     if ($value instanceof Formo_Form) {
         return $this->add_object($value->set('driver', $driver)->alias($alias));
     }
     $orig_options = $options;
     $options = func_get_args();
     $options = Formo::args(__CLASS__, __FUNCTION__, $options);
     // If a driver is named but not an alias, make the driver text and the alias the driver
     if (empty($options['driver'])) {
         $options['driver'] = Arr::get($this->config, 'default_driver', 'text');
     }
     // Allow loading rules, callbacks, filters upon adding a field
     $validate_options = array('rules', 'triggers', 'filters');
     // Create the array
     $validate_settings = array();
     foreach ($validate_options as $option) {
         if (!empty($options[$option])) {
             $validate_settings[$option] = $options[$option];
             unset($options[$option]);
         }
     }
     // Create the new field
     $field = Formo::field($options);
     $this->append($field);
     // Add the validation rules
     foreach ($validate_settings as $method => $array) {
         foreach ($array as $callback => $opts) {
             if ($opts instanceof Formo_Validator_Item) {
                 // The rules method will suffice for all Formo_Validator_Item objects
                 $field->rules(NULL, $opts);
                 continue;
             }
             $args = array(NULL, $callback, $opts);
             call_user_func_array(array($field, $method), $args);
         }
     }
     return $this;
 }
Beispiel #4
0
 /**
  * Adds a field to a form
  *
  * @access public
  * @param mixed $alias
  * @param mixed $driver. (default: NULL)
  * @param mixed $value. (default: NULL)
  * @param mixed array $options. (default: NULL)
  * @return object
  */
 public function add($alias, $driver = NULL, $value = NULL, array $options = NULL)
 {
     // If Formo instnace was passed
     if ($alias instanceof Formo_Form) {
         return $this->_add_object($alias);
     }
     if ($driver instanceof Formo_Form) {
         return $this->_add_object($driver->alias($alias));
     }
     if ($value instanceof Formo_Form) {
         return $this->_add_object($value->set('driver', $driver)->alias($alias));
     }
     $orig_options = $options;
     $options = func_get_args();
     $options = Formo::args(__CLASS__, __FUNCTION__, $options);
     // If a driver is named but not an alias, make the driver text and the alias the driver
     if (empty($options['driver'])) {
         $options['driver'] = ($driver = Formo::config($this, 'default_driver')) ? $driver : 'input';
     }
     // Create the new field
     $field = Formo::field($options);
     $this->append($field);
     return $this;
 }