$val = Validation::forge(); $val->add('brand', 'The brand')->add_rule('required'); $val->add('type', 'The type')->add_rule('required');I know I can generate a form with the Fieldset class, but I don't want to use that. If possible, I would like to be able to loop through the added fields in the Validation class (in this case brand and type) and create the textfields, something like (in a view):
foreach($fields as $key => $value) { echo "{$value}: <input type='text' name='{$key}' value='".Input::post($key)."' /><br />"; }Gives:
The brand: <input type='text' name='brand' value='...' /><br /> The type: <input type='text' name='type' value='...' /><br />The fields are saved in $val->fields but that's a protected property so I can't access it in my view.
foreach($val->field() as $field) { var_dump($field->name); }
$val->add('brand', 'The brand')->set_type('text')->add_rule('required');
echo $val->field('brand');
echo $val->field('brand');
$fieldset = $val->fieldset(); // change a template for a specific fieldset instance: $fieldset->set_config('field_template', '{field}'); // change a template for a specific field: $fieldset->field('brand')->set_template('<p>{label}<br />{field}</p>');
It looks like you're new here. If you want to get involved, click one of these buttons!