In on of my views i have the following form:
<table align="center" border="1">
<tr>
<td>Identificação</td>
<td>Conc, %</td>
<td>Classificação 67/548/CEE</td>
<td>Classificação 1272/2008 (CLP)</td>
</tr>
<tr>
<td>
<textarea rows="4" cols="30" name="componentes[0][identificacao]"></textarea>
</td>
<td>
<textarea rows="4" cols="30" name="componentes[0][conc]"></textarea>
</td>
<td>
<textarea rows="4" cols="30" name="componentes[0][classificacao_cee]"></textarea>
</td>
<td>
<textarea rows="4" cols="30" name="componentes[0][classificacao_clp]"></textarea>
</td>
</tr>
</table>
<div id="outro_curso"></div>
<p class="submit">
<button id="novo_curso">Add Curso</button>
</p>
As you can see, I'm using multidimensional arrays. I'm doing that, because when I click the "Add Curso" button I call a jquery function that generates another table like the previous one. The names of the text areas will be componentes[1][identificacao], componentes[1][conc], etc...
NOTE: I can use the button to generate tables the number of times I want.
Now, my problem is how to get this data treated in my CodeIgniter model. I tried saving the data to the $componentes array (to later insert into the database) But I guess there is something wrong with my code:
$componentes;
foreach ($this->input->post('componentes') as $key => $value){
$componentes[$key]['identificacao']=$value[$key]['identificacao'];
$componentes[$key]['conc']=$value[$key]['conc'];
$componentes[$key]['classificacao_cee']=$value[$key]['classificacao_cee'];
$componentes[$key]['classificacao_clp']=$value[$key]['classificacao_clp'];
}
Can someone give me a little help please?
EDIT:
I forgot to mention, I'm getting the error:
Invalid argument supplied for foreach().
So I don't know if my foreach ($this->input->post('componentes') as $key => $value){ is correct or if is some problem in the lines inside.
$componentes[$key]['identificacao'] = $value['identificacao'];