943,712 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1921
  • PHP RSS
Oct 12th, 2008
0

JS variable in PHP

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
yasmena is offline Offline
45 posts
since May 2008
Oct 12th, 2008
0

Re: JS variable in PHP

Click to Expand / Collapse  Quote originally posted by yasmena ...
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.
Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008
Oct 12th, 2008
0

Re: JS variable in PHP

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['user_input']
or
$_POST['user_input']
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['user_input'])
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.
Reputation Points: 37
Solved Threads: 3
Junior Poster in Training
HazardTW is offline Offline
71 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Bots as users + PTC Site
Next Thread in PHP Forum Timeline: about CakePHP Development





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC