Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Applying css to model's form fields?

I am using the form_fields method on model to get its fields and creating a form for frontend but I want to apply some css to fields, how can I achieve that? And what's the use for values array? Can we pass same parameters we pass for when creating fields with form_builder class?

Comments

  • edited June 4

    The $values array are the values saved for the record. You can use it to check for example that it even exists to see if you want to differentiate between the create and edit views of your forms. Regarding adding CSS for a particular field, you can specify a 'css' parameter for your field which should include the path to the css file found in fuel/assets/css/. So if you had a css file called 'my_field.css', you would add the following parameter to your field:

    $fields['my_field']['css'] = 'my_field.css';
    
  • Okay but I want to apply classes to that field of bootstrap. Is there any way to define that and the css property you are telling me to add is after I receive the $fields array from form_fields method?

  • The example above was referring to is a layout's fields definition in MY_fuel_layouts.php or in a model's form_fields() method that should return a $fields array. You can also specify a "style" or "class" parameter to most field types as well:

    $fields['my_field']['css'] = 'bootstrap.css';
    $fields['my_field']['style'] = 'width: 300px;';
    $fields['my_field']['class'] = 'form-control';
    
  • Okay I will try with that. Thanks

Sign In or Register to comment.