Welcome Guest, Not a member yet? Register   Sign In
Help with using jQuery for dynamical inputs
#1

[eluser]Unknown[/eluser]
Hi there!
This is my first question, i would be very pleased if you can help me.

I have to catch the values of a set of dynamic inputs, i am generating the inputs with jQuery. I dont know if it's a good solution to use the same name for all with brackets at the end like this:

Code:
<!-- first set of entries -->
<input type="text" name="nombre_contacto[]">
<input type="text" name="mail_contacto[]">

<!-- second set of entries -->
<input type="text" name="nombre_contacto[]">
<input type="text" name="mail_contacto[]">

<!-- etc... -->

Or just use a counter at the end of the name, like this:

Code:
<!-- first set of entries -->
<input type="text" name="nombre_contacto1">
<input type="text" name="mail_contacto1">

<!-- second set of entries -->
<input type="text" name="nombre_contacto2">
<input type="text" name="mail_contacto2">

<!-- etc... -->


How i can catch every single item at my controller? it's this possible?

Thanks!
#2

[eluser]cideveloper[/eluser]
personally I would do it like this

Code:
<input type="text" name="entries[0][nombre_contacto]">
<input type="text" name="entries[0][mail_contacto]">

<input type="text" name="entries[1][nombre_contacto]">
<input type="text" name="entries[1][mail_contacto]">

then you get a nice array in the $this->input->post('entries'). print_r($entries) gives you the below code that you can loop through

Code:
Array
(
    [0] => Array
        (
            [nombre_contacto] => a
            [mail_contacto] => b
        )

    [1] => Array
        (
            [nombre_contacto] => c
            [mail_contacto] => d
        )

)




Theme © iAndrew 2016 - Forum software by © MyBB