Form submit to xml sheet and signature

Trying to take html form field entries and signature (plug in) to xml master sheet for event registration form.

Here is HTML form:

<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>
<form action="form-to-xml.php" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit"> 
</form>
</body>
</html> 

Here is my PHP:

<?php
$fname = $_POST['first_name'];
$lname = $_POST['last_name'];
$email = $_POST['email'];
$message = $_POST['message'];

$xml = new DOMDocument('1.0', 'utf-8');
$xml->formatOutput = true;
$xml->load(???);

$element = $xml->getElementsByTagName('input')->item(0);

$fname = $element->getElementsByTagName('fname')->item(0);
$lname = $element->getElementsByTagName('lname')->item(0);
$email = $element->getElementsByTagName('email')->item(0);
$message = $element->getElementsByTagName('message')->item(0);

$newItem = $xml->createElement('reports');

$newItem->appendChild($xml->createElement('fname', $_POST['fname']));
$newItem->appendChild($xml->createElement('lname', $_POST['lname']));
$newItem->appendChild($xml->createElement('email', $_POST['email']));
$newItem->appendChild($xml->createElement('message', $_POST['message']));

$xml->getElementsByTagName('form')->item(0)->appendChild($newItem);

$xml->save('???');

echo "Data has been written.";

?>

My issue is I keep getting a line 14 error and I don’t know how to refer to the xml master sheet in PHP I created in Excel and added the form fields?

Eventually, I would like to add a signature field and have that saved with form submit to users email and master email both…

You really should format your PHP code to a readable format like the following:

<?php

require_once '../private/initialize.php';

use Library\Trivia\Trivia;

/* Makes it so we don't have to decode the json coming from JQuery */
header('Content-type: application/json');

$trivia = new Trivia();

$data = [];

$data['id'] = htmlspecialchars($_GET['id']);
$data['answer'] = htmlspecialchars($_GET['answer']);

if (isset($data['id']) && isset($data['answer'])) {
    $result = $trivia->check($data);
    output($result);
}

function errorOutput($output, $code = 500) {
    http_response_code($code);
    echo json_encode($output);
}

/*
 * If everything validates OK then send success message to Ajax / JavaScript
 */

function output($output) {
    http_response_code(200);
    echo json_encode($output);
}

You will get better responses to your question(s).

I thought I did but when I hit reply to post the code, it all fell into regular text format…

Sponsor our Newsletter | Privacy Policy | Terms of Service