Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Observer after validation
  • Hello everyone,

    I have a numeric field but it is displayed with a mask.
    Mysql: 96503290  int(08)
    Web form: 96503-290

    I would like to create an observer that before validation I can clean the variable.

    Is it possible?
  • Yes, why not. Just define your observer before you run the validation, or define the validation observer.

    if that is all, a simple:

    $object->value = (int) str_replace('-', '', $object->value);

    would do the job (assuming $object is the model object in the prototype of your observer method).
  • But what the event I use to launch observer? Do you have a example APP?
  • Depends on how you run validation.

    If you use the validation observer, it's defined in your model (most logical is on before_save), and you define your observer before it.

    If you run validation by hand, either by manually defining the rules in your controller (or in a model method like oil generates), or through a fieldset, you can't use an observer.

    In those cases, alternative is a validation rule that validates the input and input format, and returns the normalized result (validation rules can modify the value to be validated too).
  • But, How can I normalized value of variables? I dont find anything in the documentation.
  • I can't comment if I don't know what you do.

Howdy, Stranger!

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

In this Discussion