Satch3000
Satch3000

Reputation: 49422

Save Form to JSON

I have a form and need to submit it and save the data as a JSON file. Is it possible? If so how please?

Here is my simple form below.

<form action="#" method="">
<div data-role="fieldcontain">
<label for="date">Date Input:</label>
<input type="date" name="date" id="date" value=""  /><br /><br />
<label for="textarea">Event:</label>
<textarea cols="40" rows="8" name="textarea" id="textarea"></textarea>
<input type="submit" value="save to json" />
</div>      
</form>

Upvotes: 3

Views: 8262

Answers (3)

sod
sod

Reputation: 3928

<?php 
  $file = dirname(__FILE__).'/form-data-'.time().'-'.rand(1000,9999);
  file_put_contents($file, json_encode($_REQUEST));
?>

Upvotes: 7

Valerij
Valerij

Reputation: 27758

just use json_encode function like this json_encode($_POST)

Upvotes: 1

Peeter
Peeter

Reputation: 9382

Read this post on google http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/

I found it by googeling "jquery serialize form"

Upvotes: 2

Related Questions