How to create a form that can add new text fields within the form dynamically

0

I'm putting together a Real Estate site in launch, where one of the fields is "units." This drives field can have multiple drives, eg:

A - 1 dormitorio - 50m²
B - 2 dormitorios - 70m²

Currently it is inserted in a text area field in the Table Releases:

if(isset($_POST['enviar'])){    
    $nome = $_POST['lancamento'];
    $unidades = $_POST['unidades'];
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    $query = ("
        INSERT INTO lancamentos (nome, unidades) VALUES ('{$nome}', '{$unidades}')
    ");
    $db->setQuery($query);
    $db->execute();
    } 

echo '
<form method="POST">
<input type="text" name="lancamento">
<textarea name="unidades"></textarea>
<button type="submit" name="enviar">Enviar</button>
</form>';

But I wanted each drive to be inserted as a line in the "drives" table. I thought of having a "Add Drive" button there every time I click it it opens a set of inputs (title, bedrooms, footage).

Each release has a different amount of units, sometimes it can only have one, others can have 3, so the need to go adding new units. Then when I click submit, it registers the posting in the table releases and the units in the units table, it would look like in the example below:

tabela lancamentos
id|nome
1 |Lançamento Brooklin

tabela unidades
id|idlancamento|nome|dormitorios|area
1 |    1       | A  |    1      | 50
2 |    1       | B  |    2      | 70

I do not know how to do this "dynamic" part of adding units

    
asked by anonymous 10.09.2018 / 17:01

0 answers