Welcome Guest, Not a member yet? Register   Sign In
two form in the same page - validation?
#1

[eluser]mk-dev[/eluser]
i hope this is the right place to ask and discuss this issue.
i tried to put two form on the same page, but i got into trouble with validation. the source of the problem seems to be that there's one validation object per framework, and rules from the two forms are mixed together.

i know i could get around it with ifs on the controller side, but i don't like this approach.

i tried other libraries besides the default one, but they seem to share the same one-validator approach. so before i reinvent the wheel, i'd like to know if there's something i just overlooked, if somebody else already fixed this problem. i tried to cook my own recipe, and would like to share it if somebody is interested in it (it's still quite beta).

my recipe is based on somebody else's solution (it is called form_generation class, i wish to find the link to give credit to its author), adapted to codeigniter 2.1, and with my personal improvements, which are:
- the business of defining a form and validating it is divided in 4 objects:
-- the form (container of widget with associated rules)
-- the validator (which decides if the form validates or not)
-- the validation rule library (which contains the function to validate each rule)
-- the html widget library (which contains the form controls)
- validation is divided in 3 step:
-- precheck (like trim)
-- proper validation (max_lengh, is_numeric, valid_email)
-- postcheck (like ucfirst, strtoupper)
- the four libraries are not pulled the usual way ($this->load->library), but with a require.

this way you can separately extend the validator algorithm (stop at first error, evaluate all rules, etc), the validation rules, or the widgets without overriding the whole thing.
javascript validation was already there (in the library that i derived from) and doesn't need any extra code in the controller.






Theme © iAndrew 2016 - Forum software by © MyBB