marccv1 Posted January 3, 2015 Share Posted January 3, 2015 Hi! I need to make a little signup form that contains 2 textbox for name and birthday and 2 buttons for submit and export to xml. When the user clicks on the export to xml button, there must be an xml file containing the information entered by the user that can be downloaded. I'm not really familiar to php but can you give me an idea on how to make this possible ? thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/293636-html-to-xml/ Share on other sites More sharing options...
Solution hansford Posted January 3, 2015 Solution Share Posted January 3, 2015 Here is an ugly, down and dirty way example. Not downloadable (copy and paste), zero formatting etc.. <?php if (isset($_POST['submit'])) { // grab your post values, do DB interactions etc. echo 'Form submitted successfuly.'; exit(); // or redirect to another page } elseif (isset($_POST['xml'])) { $name = $_POST['name']; $birthday = $_POST['birthday']; echo '<pre>'; echo htmlspecialchars('<?xml version="1.0"?>'); echo htmlspecialchars('<person>'); echo htmlspecialchars("<name>$name</name>"); echo htmlspecialchars("<birthday>$birthday</birthday>"); echo htmlspecialchars('</person>'); echo '</pre>'; exit(); } ?> <html> <head> </head> <body> <form name="form" method="post" action="index.php"> Name:<input type="text" name="name"><br /> Birthday:<input type="text" name="birthday"><br /> <input type="submit" name="submit" value="submit"> <input type="submit" name="xml" value="export to xml"> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/293636-html-to-xml/#findComment-1501631 Share on other sites More sharing options...
marccv1 Posted January 4, 2015 Author Share Posted January 4, 2015 Here is an ugly, down and dirty way example. Not downloadable (copy and paste), zero formatting etc.. <?php if (isset($_POST['submit'])) { // grab your post values, do DB interactions etc. echo 'Form submitted successfuly.'; exit(); // or redirect to another page } elseif (isset($_POST['xml'])) { $name = $_POST['name']; $birthday = $_POST['birthday']; echo '<pre>'; echo htmlspecialchars('<?xml version="1.0"?>'); echo htmlspecialchars('<person>'); echo htmlspecialchars("<name>$name</name>"); echo htmlspecialchars("<birthday>$birthday</birthday>"); echo htmlspecialchars('</person>'); echo '</pre>'; exit(); } ?> <html> <head> </head> <body> <form name="form" method="post" action="index.php"> Name:<input type="text" name="name"><br /> Birthday:<input type="text" name="birthday"><br /> <input type="submit" name="submit" value="submit"> <input type="submit" name="xml" value="export to xml"> </form> </body> </html> thank you very much for this example. Quote Link to comment https://forums.phpfreaks.com/topic/293636-html-to-xml/#findComment-1501674 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.