Jump to content

html to xml


marccv1

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/293636-html-to-xml/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/293636-html-to-xml/#findComment-1501631
Share on other sites

 

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.

Link to comment
https://forums.phpfreaks.com/topic/293636-html-to-xml/#findComment-1501674
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.