So I am a little confused on the three-way relationship between the Fieldset, Validation, and Form classes. In your docs it mentions that Fieldset will use both Validation and Form to do the work, so as I understood it Form and Validation working together make up Fieldset. However, I also noticed that in the Validation factory, the Fieldset factory method is called. So how are these three classes working together? It seems that both Feildset and Validation both need each other.
The Fieldset class is used to model fields with rules, properties, values, etc.
The Form class can turn a Fieldset instance with its field objects into a HTML Form. While the Validation class uses the Fieldset instance to know which fields to check and what the rules are.
One thing that was not obvious to me and I initially found confusing is that you can access the various classes from each other. For example, if you create an object of class Fieldset like this:
$f = Fieldset::factory('form_example')->add_model('Model_Examples', $example_id, 'set_form_fields_example');
You can get the associated Form like this:
$form = $f->form();
You can get the associated Validation like this:
$val = $f->validation();
You can get the associated Fields like this:
$fields = $f->field(); OR $field = $f->field('field1');
But you can also get access in other ways. From the instance of the validation, you can get the associated fieldset and fields like this:
$fset = $val->fieldset();
$fields = $val->field();
From the instance of the form, you can get the fieldset and the fields like this:
$fset = $form->fieldset();
$fields = $form->field();