I have a form and I want to save the entries in a text file on the server when a submission is done.
The jquery I'm using is:
$(document).ready(function(){
localStorage.clear();
$("form").on("submit", function() {
if(window.localStorage!==undefined) {
var fields = $(this).serialize();
localStorage.setItem("eloqua-fields", JSON.stringify( fields ));
alert("Stored Succesfully");
$(this).find("input[type=text]").val("");
alert("Now Passing stored data to Server through AJAX jQuery");
$.ajax({
type: "POST",
url: "backend.php",
contentType: 'application/json; charset=utf-8',
data: {data: fields},
success: function(data) {
$('#output').html(data);
}
});
} else {
alert("Storage Failed. Try refreshing");
}
});
});
And the PHP I'm using is:
<h1>Below is the data retrieved from SERVER</h1>
<?php
date_default_timezone_set('America/Chicago'); // CDT
echo '<h2>Server Timezone : ' . date_default_timezone_get() . '</h2>';
$current_date = date('d/m/Y == H:i:s ');
print "<h2>Server Time : " . $current_date . "</h2>";
$dataObject = $_POST['data'];
$json = json_decode($dataObject);
echo $json;
file_put_contents('your_data.txt', $json);
?>
You can see the live version of the form here: http://hackingarticles.com/marketer/
The problem is that my code is not posting any data to http://hackingarticles.com/marketer/your_data.txt
I've been trying to solve this for so long but it's just not working for me.
Any help is appreciated.
Cheers