Save web form info to xml?



I'm from a design background and only really have experience with HTML and CSS so I'm very new to anything involving PHP and can only grasp chopping and changing bits of code at best of times.


I have found some PHP code that allows me to create a web form that when used, includes the users name, email, email subject and email body - this has been tested and works just fine and I'm receiving emails from the form with no problems.


What I want to do now is have the form create/update an XML file that I have hosted with the users info every time someone uses the form.


I tried searching and couldn't really find anything that worked.


My PHP:



<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];

if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
die ("Use back! ! ");
}

$todayis = date("l, F j, Y, g:i a");

$attn = $attn ;
$subject = $attn;

$notes = stripcslashes($notes);

$message = "
Subject: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
";

$from = "From: $visitormail\r\n";


mail('youremail@website.com', $subject, $message, $from);

?>


I found this PHP and tried adjusting it to work with my code but it doesn't seem to work:



<?php

$file="test_xml.xml";

$visitor="Name";
$ip="IP";

//load xml object
$xml= simplexml_load_file($file);

//assign name
$xml->auth->ids = $visitor;

//assign ip
$xml->auth->key = $ip;

//store the value into the file
file_put_contents($file, $xml->asXML());

?>


Am I on the right track at all?


No comments:

Post a Comment