Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Use Validation without Fieldset
  • Is there any way of using the Validation class without using the Fieldset class?
    In the docs all examples of Validation involve using a Fieldset to generate the form. I can't use the Fieldset because I need the labels to be above the text fields but Fieldset generates the form in a table and forces the labels to be opposite the text fields. If Validation can't be used without Fieldset is it possible to modify the code that is generated by Fieldset so that I can remove the table? Thanks
  • If I look at http://docs.fuelphp.com/classes/validation/validation.html, I don't see any mention of a fieldset class. Forge a validation object, add the fields, run it. Job done. As to your fieldset remark, the fieldset form is generated using a template defined in your config/form.php. If you want to change the template, copy it from core/config to app/config and modify it. You can also pass a custom config to the fieldset when you forge it, or use the set_config() method to define a custom form at runtime. I've got apps that have several definitions in a config file, which I pass on to the fieldset using \Config::get('forms.formname') which will return an array similar to the one below. Remember, the power of FuelPHP is that everything is configurable and extendable. Including this. I have an app with a template that looks like this
    return array(
     'prep_value'   => true,
     'auto_id'    => true,
     'auto_id_prefix'  => 'form_',
     'form_method'   => 'post',
     'form_template'   => "\t\t{form_open}\n<dl>{fields}</dl>\n\t\t{form_close}\n",
     'field_template'  => "\t\t\t<dt>{label}</dt> <dd>{field} {error_msg}</dd>\n",
     'multi_field_template' => "\t\t\t{group_label}{required}\n {fields}\t\t\t<dt>{label}</dt> <dd>{field}</dd>{fields}",
     'required_mark'   => '*',
     'inline_errors'   => true,
     'error_template'  => '<div class="error">{error_msg}</div>'
    );
    
    and using css I can position the labels, fields and error messages exactly where I want them (which is label above the field, error message behind it.
  • Thanks for the quick reply, very helpful info.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion