Welcome Guest, Not a member yet? Register   Sign In
best practices on Form Reuse - keeping all forms in a central location with validation
#43

[eluser]JoostV[/eluser]
@chuckleberry:
A bit late, but no, in my example you don't have to alter the code in the library at all. The only thing you alter for every form is
-set up an an array in the controller
-initiate a new form object in the controller
-process the form, like below
Code:
if ($form->metadata['validated'] == true) {
    // process from using the values in associative array $form->form_results, e.g.
    // $this->db->set($form->form_results);
    // etc.
}
else {
    // Load view and pass $form->form_elements
}

In the view you will have an array of form inputs ($form->form_elements) that you can loop through for display. You can write a generic function for this display as well.

Works like a charm. And because the $form object has an ID you can use multiple forms in a single page, also widgets. All that you alter is an array in the controller and the code that you need to process the form.


Messages In This Thread
best practices on Form Reuse - keeping all forms in a central location with validation - by El Forum - 07-26-2008, 02:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB