Skip to content
Advertisement

How to merge static and dynamic forms together in php?

The my project has two forms. The first one is a static form that is used to collect user information (Form One inserts data into a table named, master). Second form is a dynamic form which collects additional information such as dependents (Form Two inserts data into a table named, dependents).

formone.php code:

JavaScript

formtwo.php code:

JavaScript

save.php code (This is for formtwo.php):

JavaScript

I want these two forms consolidated, So, they can be put on the same webpage. Basically, I want them to be submitted with one button instead of having two different submit buttons.

Advertisement

Answer

put all the form inputs inside a single set of <form> tags.

JavaScript

You’ve still got multiple forms and submit them separately, so you need to combine them to one and submit them as one

JavaScript

var formdata = $("#my-single-form").serialize(); //etc

Once you’ve done this implement some checks for your data – e.g. check $_POST["duserid"] and any other required variables are set before you do any inserting.

Then, and with some immediate urgency go and look up prepared statements and implement them

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement