469,890 Members | 1,428 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

posting form data from dynamically created form elements


I have a form whose elements are created dynamically on selection, i.e. the form has only text boxes and the number of text boxes depends on the users selection, if user selects 3 then 3 dynamic text boxes are created and if user selects 4 then 4 dynamic text boxes are created and so on. Here is the code I am using to dynamically create the text boxes:

Expand|Select|Wrap|Line Numbers
  1. echo ("<form name='exam' action='exam_2.php' method='POST'>");
  2. for ($j=0;$j<sizeof($namearr);$j++){
  4.     echo ("<tr>");
  5.     echo ("<td>".$namearr[$j]."</td>");
  6.     echo ("<td>");
  7.     echo ("<input type='text' name='element' size='8'>");
  8.     echo ("</td>");
  9. }
  10. echo ("<input type='submit' name='exam_sub' value='submit'>");
  11. echo ("</form>");
My problem is I want to send the form elements to next page i.e. exam_2.php when submit button is clicked, I am using below code on exam_2.php page to get the data of text boxes:

Expand|Select|Wrap|Line Numbers
  1. $element = $_POST['element']; 
  2. echo $element; 
The $element contains nothing, should I treat $element as an array, I need all the values of textboxes, how will I get it.

Any help is greatly appreciated. Please give me some suggestions or coding examples.

With regards,
Sep 26 '09 #1
2 3874
1,654 Expert 1GB
Change line 7 as:
Expand|Select|Wrap|Line Numbers
  1. echo ("<input type='text' name='element[]' size='8'>");
In exam_2.php, see what is being posted with code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo "<pre>";
  3. print_r($_POST);
  4. echo "</pre>";
  5. ?>
Sep 27 '09 #2
Thanks hsriat, its working!!!
Sep 29 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Ittay Dror | last post: by
1 post views Thread by Will | last post: by
27 posts views Thread by Nicholas Couch | last post: by
5 posts views Thread by monomaniac21 | last post: by
9 posts views Thread by student4lifer | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.