How to Validate Using Saved Data from Database Instead of Post?
Created 6 years ago by mattcdavis1

I have a multi-step front-end form that breaks down a stream into 5 tabs of fieldsets and saves each set independently using skips to handle validation for each step. When a user clicks a certain button that is only available on the last step, i want to validate all steps after the last step has been validated and saved.

At the point that i want to validate the entire form, all of the data would have been saved to the database already. I want to validate the form using the existing saved data. What is the best way to accomplish this?

mattcdavis1  —  6 years ago

This is my current approach but i'm not to excited about it since it involves copy / pasting out of core method.

https://gist.github.com/mattcdavis1/4f1bf7042608bf6c7c81540b988f08e0

ryanthompson  —  6 years ago

I have been sitting here thinking about this and I agree we need to be able to extract the validator used out of the system.

It looks like you're really close to a great solution but we need a way to pass in extra values. I think what you have is great - thoughts on getting those values in there additionally? I am wondering if there is some organization we could do to make the assembly of the validator occur elsewhere and then get it and submit our own values to run.

mattcdavis1  —  6 years ago

working on this - will post back. Looks like my initial attempt is flawed

mattcdavis1  —  6 years ago

argh - i still haven't been able to find a good way to do this. especially factoring in repeaters.

mattcdavis1  —  6 years ago

For now i've just created a "Steps Completed" checkbox field and required all 5 checkboxes to be checked for the final steps (checkboxes are checked programmatically after validation). I'm not excited about this approach but it should be good enough for now. Would really like to have a way to validate a model based on it's current state (regardless of $_REQUEST state) like $model->validate().

ryanthompson  —  6 years ago

@mattcdavis1 I'll look into it! I've had some code that piggy backs on it somewhere I'll see if I can dig it up.