I need to help with this code. I have a form. Submitted data is saved in XML file and then inserted into the table below the form. I have created “edit” and “delete” button for each line of the table, but I can not solve How to make “edit” button functional?? Here is a part of HTML:
<form action="" method="POST"> <input type="hidden" name="id" value=""/> <p>fname:</p> <input type="text" name="fname"/><span class="error"><?php echo $ errors['fname'] ?></span> <p>lname:</p> <input type="text" name="lname"/><span class="error"><?php echo $ errors['lname'] ?></span> <p>street:</p> <input type="text" name="street"/><span class="error"><?php echo $ errors['street'] ?></span> <p>city:</p> <input type="text" name="city"/><span class="error"><?php echo $ errors['city'] ?></span> <p>postcode:</p> <input type="text" name="postcode"/><span class="error"><?php echo $ errors['postcode'] ?></span> <p>country:</p> <input type="text" name="country"/><span class="error"><?php echo $ errors['country'] ?></span> <p>e-mail:</p> <input type="text" name="email"/><span class="error"><?php echo $ errors['email'] ?></span> <p>phone:</p> <input type="text" name="phone"/><span class="error"><?php echo $ errors['phone'] ?></span> <input type="submit" value="SUBMIT"/> </form> <?php $ document = new DOMDocument("1.0", "utf-8"); if (is_file('form_data.xml')) { $ document->load("form_data.xml"); $ users= $ document->getElementsByTagName("user"); echo "<table>"; echo '<tr>'; foreach($ users->item(0)->childNodes as $ data) { echo "<th>".$ data->nodeName."</th>"; } echo "</tr>"; foreach($ users as $ key => $ user){ echo "<tr>"; foreach($ user->childNodes as $ data) { echo "<td>". $ data->nodeValue ."</td>"; } echo "<td> <a href='?id={$ key}&action=edit' class='buttons edit'>EDIT</a> <a href='?id={$ key}&action=delete' class='buttons delete'>✖</a> </td>"; echo "</tr>"; } echo "</table>"; }
And here is a part of code from functions.php file :
switch ($ _GET['action']){ case 'edit': // I need to make this part break; case 'delete': $ document = new DOMDocument("1.0", "utf-8"); $ document->load("form_data.xml"); $ user= $ document->getElementsByTagName('user')->item($ _GET['id']); $ user->parentNode->removeChild($ user); $ document->save("form_data.xml"); break; }
Edited data should be inserted back to the form. Is there anybody who can help me? Thanks in advance!