Welcome Guest, Not a member yet? Register   Sign In
How does a form validation know about the form?
#1

I might have missed something fundamental here!

I was looking at the CI tutorial for form validation (https://www.codeigniter.com/userguide3/l...n-tutorial) and I can't work out how the rules know about the form. As far as I can see, the basic workflow is:

 - from a URL, the controller is loaded
 - once the form helper has been loaded, the set_rules() function can be called as many times as desired
 - the run() function can be called
 - the return value of run() can be used to determine what view is loaded

The final step is the first time that the controller knows anything about the view, so how can the run() function (when it is called) know what view it needs to be acting upon? Does CI load the whole function, then find the form in the view that is associated with control structure of the run() function?
Reply
#2

(This post was last modified: 06-12-2017, 10:59 AM by PaulD.)

The form validation, on run, looks for the names given in the rules you set for matching inputs in the S_POST array. Your form may or may not actually submit those inputs.

For instance you set rules:

PHP Code:
$this->form_validation->set_rules('name''User Name''required|min_length[3]); 
Described simply: when you run the form validation, it will look for an input value in $_POST['name'], if it exists (required) and is longer than 3 chars (min_length) then for that rule you get a TRUE return. If it does not validate you get an associated error message returned.

If the $_POST array contains more fields, they are not referred to unless you have set a rule.

It needs know nothing about your form, your view, or what you do with that data.

Hope that helps,

Paul.

I just binged and this was the first result - I hope it helps: http://www.jquery-az.com/php-post-an-ass...uery-ajax/
Reply
#3

That makes sense (and is obvious now you say it out loud...)! Thanks for the explanation
Reply




Theme © iAndrew 2016 - Forum software by © MyBB