Welcome Guest, Not a member yet? Register   Sign In
Cloned fields insert_batch
#1

[eluser]alexaaaaaaaaaa[/eluser]
Hi all i have a problem with cloned fields

i use jquery in order to clone multiple fields , all good i've got for example something like:
Code:
<input type="text" name="mytext" id="mytext"/>
and the cloned like this
Code:
<input type="text" name="mytext" id="mytext1"/>
and so on if i add more ..the id gets incremented.

In my view form i also store the value of how many times the form has been cloned, and in my controller i don't get those values of my cloned fields i've tryed even the print_r($this->input->post()); but i only get the values of non cloned fields.

Should i say that i know that those cloned fields are in the form...don't know what's the problem maybe some advice...
Thank you,
Alexa
#2

[eluser]aquary[/eluser]
ID does not matter. It was only about you were cloning an input which is not...arrayable. You see that the name is the same? Because of that, you'll always got only 1 value from a field with that name.

Try adding a bracket, then clone it.

Code:
<input type="text" name="mytext[]" id="mytext"/>

Else, if you'd like to have separate variable, you'd have to somehow append the name with a counter instead. PHP wised, the first method is easier to retrieve posted data.
#3

[eluser]alexaaaaaaaaaa[/eluser]
[quote author="aquary" date="1330328336"]ID does not matter. It was only about you were cloning an input which is not...arrayable. You see that the name is the same? Because of that, you'll always got only 1 value from a field with that name.

Try adding a bracket, then clone it.

Code:
<input type="text" name="mytext[]" id="mytext"/>

Else, if you'd like to have separate variable, you'd have to somehow append the name with a counter instead. PHP wised, the first method is easier to retrieve posted data.[/quote]

Thank you but now i'm getting an error i do this
Code:
for($i=0;$i<=3;$i++)
{
$data[] = array(
'field' => $this->input->post('text'),
'filed2' => $this->input->post('user')
)
}
$this->db->insert_batch('table', $data);




Theme © iAndrew 2016 - Forum software by © MyBB