Add Form Dinamicamente PHP

0

I have a form that keeps for (1) Company (N) Branches. The point is that I do not know how to do to add N number of branches according to the user.

As an example:

<form action="../Logica/registrarResiduos.php" method="post" onsubmit="return verifOpt()">

<h2>6)A .DATOS DE EMPRESA:</h2>
<label>Razon Social: </label> <input type="text" id="txtRS" name="razonsocial" maxlength="50" required="required"/>

<h2>6)A .DATOS DE SUCURSAL:</h2>
<label>6)A.1. Domicilio: Calle:</label><input type="text" name="calle1" maxlength="50"  required="required"/>

In PHP I use $_POST['razonsocial'] for the name of the company and $_POST['calle1'] for the street of the branch.

How do I make the user add as many branches as he wants? (without having to generate the fields with JavaScript and then having to travel with PHP since the form is large and it would take me a lot of work to do that).

    
asked by Pablo Chaco 18.04.2016 в 16:20
source

2 answers

0

You can use ajax to send the data to the server and save the data of the branch, when saving the branch you could show an alert with javascript informing that it has been saved correctly, once this is done you can continue inserting data as many times as you want with the same form.

I recommend that you review information on: Single page applications (SPA) here a link: link

    
answered by 18.04.2016 / 17:55
source
0

PHP is a language that runs on the server, so that what you send to the user is the final page. You need to make a function with a client language such as JavaScript or, if you do not want, you can make an intermediate page that asks you the number of branches you want to enter and when you send it you send a page with all the fields made. Anyway, even if you have a large number of fields in the form, the function would only write a piece of code about the area you want from the HTML.

But anyway you need to process it on the server beforehand if you want to do it with PHP alone.

I hope it helped you!

    
answered by 18.04.2016 в 16:28