I have a form that is processed using PHP code. Its essence is that the person fills the fields, clicks "create!" and in the table with the lobby line is created with the lobby, which created this person. The string is created with the following jQuery code:

$(".submit").click(function(event) { $("#lobbies-list").find("tbody") .append($("<tr>") .append($(" <td>1</td> <td>' .$_SESSION['USER_NAME'].' </td> <td>**Тут должен выводится статус (status)**</td> <td>1\2</td> <td>**а тут ставка** (bet)</td> <td><span>играть!</span></td>") ) ); }) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form method="POST" action="/play" class="animation-form"> <input type="text" id="status" name="status" maxlength="23" pattern="{0,23}" placeholder="Статус"> <input type="text" id="bet" name="bet" pattern="[\d+(\.\d{2})?]{1,10}" placeholder="Ставка [формата 9.99]" required> <input type="submit" name="enter" value="создать!" class="submit"> </form> 

The problem is that the variable ' .$_SESSION['USER_NAME'].' It is correctly displayed in the newly created line, but the same $_POST['status'] , if inserted into the script, does not work. How to make so that in the created row of the table, data which was entered by the user into the form was displayed?

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

You cannot transfer a JS line to several lines of a document, from where you get $_SESSION in the JS code, it’s not at all clear (maybe this is part of the PHP variable), it would remove an example to work. I added a block where to insert and why the form was sent to you is also not clear if you want to simply withdraw.

 $(".submit").click(function() { $("#lobbies-list").find("tbody").append( $("<tr>").append( $("<td>1</td> <td>имя</td> <td>" + $('.animation-form #status').val() + "</td> <td>1\2</td> <td>" + $('.animation-form #bet').val() + "</td> <td><span>играть!</span></td>") //строка в одну строчку ) ); return false; //что бы форма не отправилась }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form method="POST" action="#" class="animation-form"> <input type="text" id="status" name="status" maxlength="23" pattern="{0,23}" placeholder="Статус"> <input type="text" id="bet" name="bet" pattern="[\d+(\.\d{2})?]{1,10}" placeholder="Ставка [формата 9.99]" required=""> <input type="submit" name="enter" value="создать!" class="submit"> </form> <!-- блок куда вставлять инофрмацию --> <div id="lobbies-list"> <table> <tbody></tbody> </table> </div> 

  • Thank you so much. You are the best person on earth, at least for tonight! And the form sends data to the database) - Bim Bam
  • @BimBam is used to thank here, marking the answer as useful and correct (up arrow and tick below) - Mr_Epic