kashell Posted June 28, 2009 Share Posted June 28, 2009 I'm a little bit stumped at this problem. Currently, I have a data driven form. The problem is that I need to have a way for the user to add this form as many times as the user needs. I need the "add person" button at the end to add a duplicate version of the form below, *except* the name of the select element needs to be unique since I'm storing the POST data in a 2d array. I know I need to somehow loop through the data or increment some value to add another set of form elements... I'm just not sure how. Please help. $personquery = "SELECT personid, personfirstname, personlastname FROM person ORDER BY personlastname"; $persondata = mysqli_query($dbc, $personquery); $rolequery = "SELECT roleid, roletitle FROM role ORDER BY roletitle"; $roledata = mysqli_query($dbc, $rolequery); echo '<select id="person[]"name="person[????]">'; while ($row = mysqli_fetch_array($persondata)) { echo '<option value="'. $row['person_personid'].'">' . $row['personlastname'] . ' ' . $row['personfirstname'] . '</option>'; } echo '</select><br />'; while ($row = mysqli_fetch_array($roledata)) { echo '<input type="checkbox" id="person[][]" name="role['.$row['roleid'].']['.$row['roleid'].']" value="'. $row['roleid'].'"/>' . $row['roletitle'] . ' '; } echo '<input type="submit" value="Add another person" name="add person"'; Link to comment https://forums.phpfreaks.com/topic/163986-add-a-form-element-using-a-button/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.