Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 761
Satch3000 Avatar asked Feb 20 '26 23:02

Satch3000


2 Answers

<?php 
  $file = dirname(__FILE__).'/form-data-'.time().'-'.rand(1000,9999);
  file_put_contents($file, json_encode($_REQUEST));
?>
like image 74
sod Avatar answered Feb 22 '26 13:02

sod


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"

like image 20
Peeter Avatar answered Feb 22 '26 11:02

Peeter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!