I have a 20 page document with 20 forms in it. It's organized into sections.
Section 1:
1.1 - Form 1
1.2 - Form 2
1.3 - Form 3
Section 2:
2.1 - Form 1
...etc...
I have a controller setup that looks something like this (for now):
class Section extends CI_Controller {
public function index($section_id) {
$this->section_model->_require_valid_section($section_id);
$data['view'] = "section/index";
$this->load->view('app/template', $data);
}
}
I need to build views for these 20 forms. Each form has different data. One might have "Name, Email, Phone" while the next might have "Person Name, Facility Name, Title" and they aren't related. I think it is probably silly to have a table for each form (more forms could come at any time), so I could do a table like this:
Section | Key | Value
-------------------------
1.1 name Randolph
1.1 phone 1111111111
2.1 person Junior
2.1 title Playa
I'd really like to know how I could set up my controller to handle and route requests for these forms.
Would it be ideal to just create functions for each one?
public function form_1_1() {
$this->section_model->save_1_1();
}
public function form_1_2() {
$this->section_model->save_1_2();
}
index()
could route the requests via call_user_func()
but I don't know if thats the right way to do it.
you could always just put a hidden input in each form and then inside your controller function act on what the value of the hidden field is.
Add to views in each form:
<input type="hidden" name="form_name" value="form_1" />
Add to controller:
$form_submitted = $this->input->post('form_name');
Then just use a switch or if to handle the data based on the $form_submitted
variable.
It depends on what you need to structure your data for, storage, or searching / reference later.
A quick and possible answer would be to use a single table like you already do, but reference columns like: entry_id
, form_type
, userid
, etc... data
The data
column would store the form elements/values serialized, potentially being less easy to search, but offering a clean way to store multiple form submits.
To get the data back, you would select all entry_id's with the userid, etc; and unserialize the values into arrays you could easily work with.
Your other option, would be to get something like DataMapper, and handle a one to many, or a many to many relationship between your forms.
Datamapper Reference:
http://datamapper.wanwizard.eu/