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.

How to validate multiple dates when calling $this->model->clean()?

I have a form with multiple date fields of same name, I am using jQuery Datepicker to populate dates and then posting it. I am stuck at the point when I try to call clean on my model, it cleans all texts values but it gives error on date fields.
preg_match() expects parameter 2 to be string, array given in this class MY_date_helper.php. I don't know how to pass my array indices.

Comments

  • You can overwrite your model's clean method to account for the array value.

  • I did tried what you said admin but the preg_match is being called before that I tried with on_before_validate if that was being called first but it wasn't as well. So which callback is actually being called first?

  • What line number is it erring on in the MY_date_helper? Is it the is_date_db_format() function? If so, I'm curious how it's getting to that area of the code in MY_Model.php around line 1309 since the field types that are being checked are only date and datetime which you can't store array values in.

    It roughly goes:

    $this->on_before_post();
    $this->on_before_clean($values);
    $this->clean($values);
    $this->on_before_validation($values);
    $this->validate($values);
    $this->on_before_save($values);
    $this->on_after_save($values);
    $this->on_after_post($values);
    

    Are you wanting to serialize that field?
    http://docs.getfuelcms.com/general/models#serialized

  • No, I don't want to serialize I just wanted to convert my form values for the same name into record objects, like I have degree, major and institute as array in post so I wanted to make a record object of each of them, I already have my model class for it, and wanted to use its record object which would have all these three fields.

  • Are you wanting to save those dates onto another model entirely? Perhaps something like a foreach loop on the on_after_save hook that loops through the dates to save those to another model?

  • Hello, I didn't answer your question earlier about the line of error, yes it is the is_date_db_format and it is reaching there because my field type is date, also the earlier reply would be a bit confusing as I didn't understood completely but I just want my date to go as string not as array, I have multiple fields with same name of date type, I'll try the on_before_validate as well

Sign In or Register to comment.