2

When I am trying to POST an Array Having some ploblems,

Here is my code

Thanks in advance

for(;$i>0;$i=$i-1){
    $j=$new+1;
    echo '</br>'.$j.'. <form action="3.php" method="post"/><input type="textarea" name="o[.$new]"/><input type="text" name="o2[.$new]"/><input type="text" name="o3[.$new]"/><input type="submit" value="Send"/></form></br>';
    $new=$new+1;
}

What I am trying to achive is to create dynamic number of textarea, and wait user to fill up these area, then post these datas to the "3.php" page.

<form action="3.php" method="post"/>
    <input type="textarea" name="o[.$new]"/>
    <input type="text" name="o2[.$new]"/>
    <input type="text" name="o3[.$new]"/>
    <input type="submit" value="Send"/>
</form>
7
  • Variables are not parsed inside single quoted strings. Use " Commented Jan 23, 2016 at 16:26
  • Thank you. However, that's not the main problem, The problem I have is to POST dynamic number of variables I need to take a number from a user, then create this number of textarea, wait user to fill those areas, then print the datas. Commented Jan 23, 2016 at 16:28
  • And what is the main problem? I don't see anything in a question related to the problem. Commented Jan 23, 2016 at 16:30
  • The problem I have is to POST dynamic number of variables I need to take a number from a user, then create this number of textarea, wait user to fill those areas, then print the datas Commented Jan 23, 2016 at 16:38
  • And you can't do what? Commented Jan 23, 2016 at 16:40

1 Answer 1

1

First form for posting the number of the textareas:

<form action="posting.php" method="post">
    <input type="text" name="textareasNum">
    <input type="submit" value="Send the number of textareas">
</form>


The posting.php is:

<form action="3.php" method="post">
    <?php
        $num = $_POST['textareasNum'];
        for($i = 0; $i < $num; $i++)
           {
    ?>
             <textarea name="o<?php echo $i;?>">
             </textarea>
    <?php
           }
    ?>
</form>
Sign up to request clarification or add additional context in comments.

3 Comments

First of all, thank you so much for this, It works fine! :) Last question:) How can I code to gather entered values in textareas ? I couldn't create a valiable name like o2 or o8 dynamically
Sure you can, like this: for($i = 0; $i < $num; $i++){ $data_array[] = $_POST['o'.$i];}. Now, you have all the values you want in $data_array[].
Previous code is for 3.php file. You can send the $num value using this: <input type="hidden" value="<?php echo $num;?>" /> after <form> tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.