|
| 1 | + |
| 2 | +<?php |
| 3 | + |
| 4 | + if (!isset($_POST['add_account'])) { |
| 5 | + |
| 6 | +?> |
| 7 | + |
| 8 | +<form method="post" action="" enctype="multipart/form-data"> |
| 9 | + |
| 10 | +<p id="add_field"><a class="btn btn-default" href="#">Add Rows</a></p> |
| 11 | +<table id="myTable"> |
| 12 | +<thead> |
| 13 | + <tr> |
| 14 | + <th>#</th> |
| 15 | + <th>First Name:</th> |
| 16 | + <th>Last Name:</th> |
| 17 | + <th>E-mail:</th> |
| 18 | + <th>Upload file</th> |
| 19 | + <th></th> |
| 20 | + </tr> |
| 21 | +</thead> |
| 22 | +<tbody id="container"> |
| 23 | +</tbody> |
| 24 | +</table> |
| 25 | + |
| 26 | +<input class="btn btn-default" type="submit" name="add_account" value="Submit" /> |
| 27 | +</form> |
| 28 | + |
| 29 | + |
| 30 | +<?php } ?> |
| 31 | + |
| 32 | +<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> |
| 33 | +<script type="text/javascript"> |
| 34 | + |
| 35 | + $(function(){ |
| 36 | + var counter = 0; |
| 37 | + $('p#add_field').click(function(){ |
| 38 | + counter += 1; |
| 39 | + $('#container').append( |
| 40 | + '<tr><td>' + counter + '</td><td><input name="fields['+counter+'][first]" type="text" placeholder="First Name" required/></td><td><input name="fields['+counter+'][last]" type="text" placeholder="Last Name" required/></td><td><input name="fields['+counter+'][email]" type="email" placeholder="email" required/></td><td><input id="userfile" name="fields['+counter+'][file_uploaded][]" type="file" /></td><td><input type="button" value="Remove" onclick="delRow(this)"></td></tr>'); |
| 41 | + |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + function delRow(currElement) { |
| 46 | + var parentRowIndex = currElement.parentNode.parentNode.rowIndex; |
| 47 | + document.getElementById("myTable").deleteRow(parentRowIndex); |
| 48 | + } |
| 49 | + |
| 50 | +</script> |
0 commit comments