I am working on a registration system using php. I have a form that contains user information and Certifications information. The user could click on "Add another certificate" link which will dynamically duplicate the field set of certificate information with all form input elements using the code:
<script type="text/javascript">
var i = 1;
function duplicate() {
var original = document.getElementById('certificateInfo1'); // id of first fieldset
var clone = original.cloneNode(true); // "deep" clone
clone.id = "certificateInfo" + ++i; // there can only be one element with an ID
var beforeEle = document.getElementById("addNew"); // Get the <p> element to insert the div before it a
original.parentNode.insertBefore(clone, beforeEle);
}
</script>
The problems that I faced are: 1- When the form is submitted and there is error message, the dynamically created <fieldset>
and its children is disappear. How I can keep the all dynamically created field set with its children ?
2- How can I get the data of each certificate alone to insert it in the database? because all form element will have the same name.