form_validation library and discrete functions ? |
[eluser]Monarobase[/eluser]
Hello, I'm sorry if there is a very simple answer to this one but I have read the docs, searched the wiki and searched the forum so I am positing my question here. I'm building a dynamic form which builds a form from database entries, I have made views per type of form input and am now working on the validation. My database contains collomns like : 'required' => 0 or 1 'min' => 0 (deactivated) or 1 to 99999 'max' => 0(deactivated) or 1 to 999999 I could easily build the rules lines and run something like this for each line : Code: if($db->required == 1) $rules .= ($rules == '') ? 'required' : '|required'; However the docs mention discrete functions, but I have not managed to get them to work ... This is what I have tried : Code: $this->form_validation->set_rules($v->name, $v->descr); It seems that it doesn't work like the database library though as the discrete functions are not taken into account. As you can see I have got my code working and it's more out of interest, but how are you supposed to use the "discrete" functions that the doc talks about here : http://codeigniter.in.th/user_guide/libr...ereference ? Thanks in advance
[eluser]cahva[/eluser]
I havent used those discrete functions but I have a suggestion to your code. Instead of concatinating, why not add rules to array and glue them together with '|' to finalize rules? eg. Code: $rules = array(); Something like that..
[eluser]Monarobase[/eluser]
Thankyou, I like your method and will use it but would still be grateful if someone could tell me what I'm doing something wrong with the functions ...
[eluser]WanWizard[/eluser]
Depends a bit on what you expect. All the manual says is that you can call the form validation methods directly. In which case they just return TRUE or FALSE, a return value you have to check yourself. They don't magically create rules.
[eluser]Monarobase[/eluser]
Ok Thank you, that makes a lot of sense, the method suggested above makes the code a lot more legible and "magically" building the rules like the db library does would be more fun than necessary. |
Welcome Guest, Not a member yet? Register Sign In |