Good evening, according to my understanding, your doubt can be solved with Javascript, more precisely the jQuery..
If in PHP, you want PHP to write the form, do more or less so using repetition structure for():
php form.
<?php
$numfields = $_GET["num_fields"];
echo '<form method="POST">
<! -- Repeated data --!>
';
for($i = 0; $i < $numCampos; $i++) {
echo '<label for="amox_'. $i.'">Amox '.($i+1). '</label> <input type="text" name="amox[]" id="amox_'. $i.'"><br />
';
}
echo '</form>';
?>
And in the browser you access: http://localhost/form.php? num_fields=4
And he will return:
<form method="POST">
<!-- Dados repetidos -->
<label for="amox_0">Amox 1</label> <input name="amox[]" id="amox_0" type="text"><br>
<label for="amox_1">Amox 2</label> <input name="amox[]" id="amox_1" type="text"><br>
<label for="amox_2">Amox 3</label> <input name="amox[]" id="amox_2" type="text"><br>
<label for="amox_3">Amox 4</label> <input name="amox[]" id="amox_3" type="text"><br>
</form>
Or you can do in jQuery that will become much more dynamic and visually beautiful for the user, using jQuery.append().
I hope I’ve helped.
PHP has no button or input text. This is HTML stuff, and to change dynamically in the client needs JS. Note that PHP simply processes data and mounts the server-side page. Even if it generates an HTML, it always happens before the client receives the data and interacts with the page. To change this on the client side, either use JS/Ajax and the like, or reload the/iframe page (prefer JS/Ajax, unless you need to deal with primitive systems).
– Bacco