1
1
1bubaleh2016-08-05 21:37:22
PHP
1bubaleh, 2016-08-05 21:37:22

How to get the value for the fields from the server?

Good evening, comrades!
Using the "Submit" button sent the form data to the server.
But how to make it so that when you click on the "Add field" button, the fields contain values ​​​​that have already been sent?

<!DOCTYPE html>
<html>
 <head>
   <title>!DOCTYPE</title>
   <meta charset="utf-8">
 </head>
 <body>

    <form id="forma" action="#" method="post">
<div class="div">
  <button type="button" id="add">Добавить поле</button>
  <button>Отправить</button>
</div>
    </form>


    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
   		<script>
   	
   	$(document).ready(function() {

   		current = 1;

   		$("#add").click(function() {
   		current++;


   		$("#forma").append("<div class='div'>Поле:<input type='text' id='input' size='10' name='avon' value=''></div>");


   		var avon = $("#input").attr("name");
   		var avon_current = avon + current;
   		$("#input").attr("name", avon_current); 

   		var id = $("#input").attr("id");
   		var idkod_current = id + current; 
   		$("#input").attr("id", idkod_current); 


   		});
   	});

   </script>

   <?php
    	         echo @$_POST["avon2"] . "<br>";
   		 echo @$_POST["avon3"] . "<br>";
   		 echo @$_POST["avon4"] . "<br>";
    ?>

 </body> 
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-08-05
@1bubaleh

Good evening.
Try sending data via ajax, do not clear the form after submitting or write it to cookies/session, clone the field when adding clone or substitute the value from cookies/session

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question