[eluser]datdesignguy[/eluser]
Hi all, I'm in a bit of a pickle. It should be pretty easy to answer, but I'm a little rusty and can't seem to find the answer I'm looking for.
I have a form, that allows the user to add up to 8 contact records to an application. I implemented this on the frontend with javascript, and used numbered arrays to post the data to the backend.
So, if there are 3 contact records being submitted in the form, then they would arrive into the backend as numbered arrays, 1, 2, and 3. each of those arrays have: name, title, company, email, address,phone, bio, admin_name, admin_email, admin_phone fields.
I'm trying to validate input for each of these contact records, by maintaining a hidden form field that keeps track of the id-numbers of each contact record added to the html form. So in the example above, if we have 3 contact records with id's 1,2,3, then the contents of the hidden field "cospeakers" would be: 1,2,3, (the last comma is chopped off by php in the code below)
The problem I'm having is actually two:
Somewhere validation is getting hung up on an array to string conversion (not sure where yet), and secondly is it possible to write valid rule-sets using the method I've employed in the code below (multi-dimensional rules)?
Any help you can provide on this subject is HIGHLY appreciated!
Thanks, -gregj
Code:
if($this->input->post('has_cospeaker') == 1){
$cospkrs = explode(',',rtrim($this->input->post('cospeakers'),','));
$i=1;
foreach($cospkrs as $id) {
$cospkr = $this->input->post($id);
$rules[$id]['name'] = "required|min_length[3]";
$rules[$id]['title'] = "required|min_length[3]";
$rules[$id]['company'] = "required";
$rules[$id]['email'] = "valid_email";
$rules[$id]['phone'] = "min_length[10]";
$rules[$id]['bio'] = "required|callback__bio_words";
$fields[$id]['name'] = "Co-Speaker $i Name";
$fields[$id]['title'] = "Co-Speaker $i Title";
$fields[$id]['company'] = "Co-Speaker $i Company";
$fields[$id]['email'] = "Co-Speaker $i Email";
$fields[$id]['phone'] = "Co-Speaker $i Phone";
$fields[$id]['bio'] = "Co-Speaker $i Bio";
if($cospkr['hasadmin'] == 1) {
$rules[$id]['admin_name'] = "required|min_length[3]";
$rules[$id]['admin_email'] = "valid_email";
$rules[$id]['admin_phone'] = "required|min_length[10]";
$fields[$id]['admin_name'] = "Co-Speaker $i Admin Contact Name";
$fields[$id]['admin_email'] = "Co-Speaker $i Admin Email";
$fields[$id]['admin_phone'] = "Co-Speaker $i Admin Phone";
}
$cospkrs[$id] = $cospkr;
$i++;
}
$data['cospkrs'] = $cospkrs;
$data['last_cospkr'] = $id;
unset($i,$cospkr);
}