i have a JS that generates fields on the fly
i set a counter so that i can count the no. of fields the user generated
now i need to loop through these fields
and i dont know how to use that JS variable inside PHP


for($i=0;$i< "JS VAR";$i++)

i need help plz

Recommended Answers

All 2 Replies

i have a JS that generates fields on the fly
i set a counter so that i can count the no. of fields the user generated
now i need to loop through these fields
and i dont know how to use that JS variable inside PHP


for($i=0;$i< "JS VAR";$i++)

i need help plz

You have to submit the form to a server side script then you can pull the fields in using the $_POST or $_GET superglobals.

If those fields have the same NAME, ie.
<input type="text" name="user_input">
<input type="text" name="user_input">
<input type="text" name="user_input">
<input type="text" name="user_input">

When the form that encloses these input's is submitted then the PHP variable on the server would be:
$_GET
or
$_POST
depending on your method get or post.
It will be an array containing the values of all form elements with the name 'user_input' that belongs to the form that was submitted.

In the PHP file that the form is submitted to try this:
var_export($_GET)
or $_POST, whichever you are using and it will dump the structure of array where you should see the values that you had entered into the forms before submission.
This will give you a clear idea of how to retrieve the individual values from that array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.