-2

I have a form and a button with a function that create dynamically a textfield and set the name with an index like below: corso_1 corso_2 corso_3

So.. a php function get all the value of this form and add all in an array, so how can i get all the value into the dynamic textfields?

4
  • 1
    Have you tried naming them using an array name like name="myfields[]"? Commented Jul 5, 2017 at 14:35
  • You could go through all $_GET values and pick them by a regex or what would be much easier if you name the fields corso[] corso[] this would result automatically in an array Commented Jul 5, 2017 at 14:35
  • I don't understand. Can you type some code? Commented Jul 5, 2017 at 14:37
  • If i set the name of the textfields like this: corso[0], corso[1], corso[2] The follow php code is not good $corsi = array(); $while(true){ array_push($corsi, $_POST['corso[$i]']; } Commented Jul 5, 2017 at 14:42

1 Answer 1

0

just put the all data with jquery in that dynamic textfield.by looping throught Real_data array and set index as Real_data['corso_'+i] and here i is a for loop variable.

& $('#corso') is the form id.

hope it helps.

 var data = $('#corso').serializeArray(); var Real_data = {}; //this array is used to store sorted data $(data).each(function(i,field){ Real_data[field.name] = field.value; }); 
Sign up to request clarification or add additional context in comments.

7 Comments

But how can get it from php
are showing that array on same page or on another ..??
I get the value of the dinamyc textfield and put into an array with php, those values will stored into a DB
the other theory is that use above snippet withJSON.stringify() and remove the $.each now store the data in hidden text field and when the user submits the form the hidden text field's value will be sent to php script with post or get and then u can store the data in db.
i didn't think about it!! Thank you!!
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.