Jump to content
Sign in to follow this  
marccv1

html to xml

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

Share this post


Link to post
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>

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • 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.