Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
how to create localized form with validation using ORM
  • this is my first project with FuelPHP and I'm using the ORM package to build a localized (English/French) application. I have scaffolded my (ORM) model with oil and my first question is: why do oil generates a validate function instead of validation in $_properties? I have manually added the validation inside $_properties but wonder if I need to keep the validate function. Second, I need to customize the error messages. I have translated lang/en/validation.php to lang/fr/validation.php but those messages are generic and use the input name which isn't translated, so that doesn't cut it. How can I have custom (and localized) error messages for each fileds in my model? I have wrestled with the Fieldset class but still can't wrap my head around it. If this is the solution, can someone provide a complete usage example? I also would like to implement custom validation (like check_unique) and wonder what is the proper way of doing it considering the previous requirements.
  • The scaffolding code is still quite generic so it can both support Model_Crud and ORM. You can 'overload' validation messages using the set_message() method on the validation object. It will still be a message per rule though, not a message per field. That would be quite useless because a field can have an entire list of errors, one for every rule you have defined. There is no option to set a custom message for each field/rule combination atm. I tend to store model specific validation methods in the model itself (which you then can use in the $_properties), or in a central validation class if the rules are generic and I want to use them in multiple places. Both methods are documented, so see the docs.
  • OK. If anyone is interested in a rather cheap solution, I worked around the custom error messages limitation by overriding the get_message method of the Validation_Error class. I simply added a test to check if there is a validation string (in my custom validation locale) corresponding to fieldset_name.field_name.rule_name You need to extend the fieldset class to add a get_name public method in order to retrieve the fieldset name (the property is protected) inside the Validation_Error class. Note that the ORM assign the model name to the fieldset name.
  • Revising the message system (and the fieldset class in general) has been added to the roadmap for v2.0.

Howdy, Stranger!

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

In this Discussion