Jump to content

displaying form array help


corbeeresearch

Recommended Posts

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

 

 

 

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.