There is a simple form:

<form name="test" method="post"> <p><b>Ваше имя:</b><br> <input type="text" size="40" name="user"> </p> <input type="submit" value="Отправить"> </form> 

And php code:

 <?php $name = $_POST ['user']; for ($i = 0; $i < count($name); $i++){ echo "<pre>"; echo $name; //пытался также $name[$i] echo "</pre>"; } ?> 

It is necessary that, without updating the page, each user is displayed above the form one after another after submit. But in my output, the username is replaced with a new one when a new one is entered into input-e.

  • "Trying to implement" - how? - Igor
  • From the fact that you have removed the words "I am trying to realize" from the question, it did not get any better. - Igor
  • I wrote to help implement such logic. And your comment is not at all useful for this. - Beginner

2 answers 2

Well, if without php, then so. Not tested may not work correctly

 <?php $name = $_POST ['user']; for ($i = 0; $i < count($name); $i++){ $s = $_POST['namepost'].$name."<br />"; } ?> <form name="test" method="post"> <p><b>Ваше имя:</b><br> <input type="text" size="40" name="user"> <input type="hidden" name="namepost" value="<?=$s?>"> </p> <input type="submit" value="Отправить"> </form> <?=$s?> 
  • no, that doesn't work. - Beginner
  • now tested, everything works - G.Denis
  • how exactly does not work? gives an error? or would you like to do something else? - G.Denis
  • pasted into your code and does not work. And your checked - it works! - Beginner
  • I realized what was wrong. I first had the html in the file, then the php code - and it did not work. I swapped and earned. And why? - Beginner

 $("form").submit(function(){ $("#names").html($("#names").html() + $("#user").val() + "<br />"); return false; }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="names"></div> <form name="test" method="post"> <p><b>Ваше имя:</b><br> <input type="text" size="40" name="user" id="user"> </p> <input type="submit" value="Отправить"> </form> 

  • the fact of the matter is that you need to do this on php. - Beginner