Automated Element Loading

Use the Solar_Form::load() method to load elements into a form using an external source, such as a Solar_Sql_Model object.

You can pass an arbitrary number of parameters to this method; all params after the first will be passed as arguments to the fetch() method of the loader object.

If the loader specification is a string, it is treated as a class name to instantiate with Solar::factory(); if the loader specification is an object, it is used as-is. Either way, the loader's fetch() method will be called to set the elements and attributes of the form.

The loader object itself must have at least one method, fetch(), that returns an associative array with keys 'attribs' and 'elements' which contain, respectively, values for Solar_Form::$attribs and Solar_Form::setElements().

Solar comes wiwth one automatic element loading class: Solar_Form_Load_Model. This class loads forms from Solar_Sql_Model column definitions; see the Solar_Form_Load_Model::fetch() method for a little more information.

Example use:

<?php
// create a model object
$model = Solar::factory('Solar_Example_Model_Nodes');

// create the form object
$form = Solar::factory('Solar_Form');

// use Solar_Form_Lood_Model as the adapter
$adapter = 'Solar_Form_Load_Model';

// load elements and attributes from the table columns in the model
$form->load($adapter, $model);

// populate, validate, and get values
$form->populate();
$is_valid = $form->validate();
if ($is_valid) {
    $values = $form->values();
    // and do something with the values here
}
?>