On the page there is a profile with text fields, tables and other. The user can add fields dynamically, i.e. clicks a button and another text field appears where he writes something down. Once finished - presses the send button. You need everything that he wrote to send an email . Of course, it is possible through javascript to access in turn all the elements, read their values, compose the body of the letter and send, but there are many of them ... Is it possible to get the full contents of the block where all the necessary information is located? Tried through $("#moydiv").html() - does not help.

CODE:

 <div id="app"> <div> <div> <strong> <center> Общие сведения об организации: </center> </strong> </div> <hr> <div> Наименование организации: </div> <div> <input type="text" name="" id="name_company" class="input_app"> </div> <div> Наименование объекта информатизации (ОИ): </div> <div> <input type="text" name="" id="name_oi" class="input_app"> </div> <br><center><strong>Окна:</strong></center> </div> <div> <table> <colgroup> <col width="250"> <col width="100"> <col width="100"> <col> <col width="120"> <col width="120"> </colgroup> <thead style="border: 1px solid;"> <tr> <th rowspan="2" style="text-align: center;"> Номер окна </th> <th colspan="2" style="text-align: center;border: 1px solid;">Размеры (м)</th> <th rowspan="2" style="text-align: center;border: 1px solid;">Материал</th> <th rowspan="2" style="text-align: center;border: 1px solid;">Количество сегментов стекла</th> <th rowspan="2" style="text-align: center;border: 1px solid;">Расстояние межд. стекл. (мм)</th> </tr> <tr> <th style="text-align: center;border: 1px solid;">Шир. (м)</th> <th style="text-align: center;border: 1px solid;">Выс. (м)</th> </tr> </thead> <tbody id="okna"> <tr> <td style="width: 100px; border: 1px solid; padding: 5px;"> <input name="OKNO[]" type="text" class="form__input" placeholder="№"> </td> <td style="width: 50px;border: 1px solid;padding: 5px;"> <input name="SHIR[]" type="text" class="form__input"> </td> <td style="width: 50px;border: 1px solid;padding: 5px;"> <input name="VIS[]" type="text" class="form__input"> </td> <td style="width: 100px;border: 1px solid;padding: 5px;"> <select name="MAT[]" style="height: 38px; width: 100%; border:none;"> <option value="пластик">пластик</option> <option value="дерево">дерево</option> </select> </td> <td style="width: 50px;border: 1px solid;padding: 5px;"> <input name="KOLO[]" type="text" class="form__input"> </td> <td style="width: 50px;border: 1px solid;padding: 5px;"> <input name="ORASST[]" type="text" class="form__input"> </td> </tr> </tbody> </table> <div style="margin-top: 10px"> <input type="button" name="" value="Добавить" onclick="addotss()" class="mybutton"> // эта функция добавляет строчки в таблицу </div> <form action="index.php" method="post"> <!--<input type="submit" name="tutu" value="Добавить">--> <input type="button" name="" value="отправить" onclick="sendmes()" class="mybutton"> </form> </div> 

  • Give an example of your code. In general, you make all the fields in the form, so that when you add a field, it will be added to the form. And when you press the button, submit the form via js. - Moonvvell
  • Added a code ..... - Alexander

1 answer 1

Add the name attribute to all input tags and assign the appropriate value to it:

 <input type="text" name="email"> 

In the php script of the form handler, you can access the values ​​of all fields through the $_POST global array. For example, the value of input'a, above, can be obtained as follows:

 $email = $_POST['email']; 

Where fields are added to users dynamically, add the name with square brackets to the name attribute:

 <input type="text" name="arr[]"> 

And then the array of values ​​of these fields will come to the server.

  • This is more or less clear, but not interesting ... It is interesting to just take and send yourself just a piece of the page that the user has filled in ... And run through all the elements of the page and read their values ​​for a long time ... - Alexander
  • @ Alexander, is it uninteresting? And you want how to collect the values ​​of all inputs from the page?) You can loop through all the inputs on the page, collect data from them, write to the object and send to the server. But if you add the attribute name all this will be done automatically for you. ) But if you want to write bicycles then ok) - Moonvvell
  • I just thought that it was possible to get the html of the block along with the value values ​​of the input tag. Something like $ ("body"). Html () or $ ("body"). InnerText. After all, javascript sees everything that is on the page ... Isn’t it possible to take javascript all at once with values ​​at once ??? - Alexander