corbeeresearch Posted September 2, 2010 Share Posted September 2, 2010 Consider this scenario: I'm using an ajax to make the form use only one page I got a multistep form with step3 being the result of step2, within step3 there is an "add more steps" button which duplicates step2 and step3, this can be done countless times. to complement this I added array to my input boxes something like this: <input type="text" name="name[]" id="name"/> unfortunately, I'm not sure how to approach this in the php. In the step2 going to step3, I would call the brand id and use it in the database to get the results for step3, but now it's array I added the following lines $brand = $this->input->post('brand[]'); $this->load->model('MBest'); $q = $this->MBest->getbestmatching($brand[0]); But the $brand[0] doesn't works and triggers an error. And come to think of it, if I call a $brand[0] index, then everytime a person add a new step, it will always use the id of the first result. Are there any ideas on how to fix this problem? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/212325-displaying-form-array-help/ Share on other sites More sharing options...
corbeeresearch Posted September 2, 2010 Author Share Posted September 2, 2010 I tried doing the following code in the controller that is responsible for passing step2 data to step3 $brandID = $this->input->post('brand[]'); $this->load->model('MBest'); for($x=0;$x<count($brandID);$x++) { $brand[] = $brandID[$x]; } print_r($brand); $q = $this->MBest->getbestmatching(end($brand)); unfortunately I get Array ( [0] => ) in the result. But when I look at the ajax request in firebug I found that brand did post a value. Where did I go wrong? Quote Link to comment https://forums.phpfreaks.com/topic/212325-displaying-form-array-help/#findComment-1106298 Share on other sites More sharing options...
sasa Posted September 2, 2010 Share Posted September 2, 2010 .change $brandID = $this->input->post('brand[]'); to $brandID = $this->input->post('brand'); Quote Link to comment https://forums.phpfreaks.com/topic/212325-displaying-form-array-help/#findComment-1106303 Share on other sites More sharing options...
corbeeresearch Posted September 2, 2010 Author Share Posted September 2, 2010 Thanks it works! Unfortunately, I found another problem I realize that my form has a back and next button. That means that when I clone the step2 and step3, going back to an earlier step2 would get the latest step3 brand id instead of the current one. Then using end($brand) would not be applicable Is there a way to make the code understand which index it should be? Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/212325-displaying-form-array-help/#findComment-1106305 Share on other sites More sharing options...
sasa Posted September 2, 2010 Share Posted September 2, 2010 can you post your form code Quote Link to comment https://forums.phpfreaks.com/topic/212325-displaying-form-array-help/#findComment-1106325 Share on other sites More sharing options...
corbeeresearch Posted September 2, 2010 Author Share Posted September 2, 2010 It's hideously long, is it okay? Quote Link to comment https://forums.phpfreaks.com/topic/212325-displaying-form-array-help/#findComment-1106338 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.