PHP program flow for dynamically generated html inputs posting to DOMPDF

363 views Asked by At

I am new to programming and have a control flow question. I am working with php and the DOMPDF library to generate PDFs.

I have a jQuery script that will dynamically generate input fields for an additional SET of inputs (up to 10 sets [20 inputs]). This leaves me with the following dilemma. I have successfully tested that the following if statement will serve the functionality I expect:

if ($additional_input1!='') 
    $html = str_replace('{{ADDITIONAL_INPUT1}}', $additional_input1, $html);
else
    $html = str_replace('{{ADDITIONAL_INPUT1}}', null, $html);
if ($additional_input2!='') 
    $html = str_replace('{{ADDITIONAL_INPUT2}}', $additional_input2, $html);
else
    $html = str_replace('{{ADDITIONAL_INPUT2}}', null, $html);

However, this would make my code look messy. Can you please provide with suggestions as to what the most efficient way to tackle this program flow situation is?

1

There are 1 answers

1
Goikiu On

if you know a little of JQuery you know how to change the "name" of the input.

If you give to all those "textfield" (i do not know what those are) the name test you can do something like

<input type="text" name="field[]"/>
<input type="text" name="field[]"/>
<input type="text" name="field[]"/>
<input type="text" name="field[]"/>

On your php page (assumed your form use a post method) you can retrieve the data with this:

$count = count($_POST['field]);
for ($i = 0; $i < $count; $i++){
 $post[] = $_POST['field];
}

After this you will have an array with name $post with all those field, please remember that this code was only for giving you an idea, it can or can't work.