最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Saving html form data to file - Stack Overflow

programmeradmin3浏览0评论

I am using Trisquel 7.0. I've some basic knowledge about html and JavaScript. Now I want to save html form data to file (Also interested in loading/filling html form from file).

I searched and found that This would be possible with php etc. But I don't know How to. As a beginner at this time, I would like to save only text information in text-file simply from html form.

Below I am writing simple example with simple html form and JavaScript function (without any action)

<html>
<form name=myform>
<input type=text name=mytext>
<input type=button value=save onClick=saving()>
</form>
<script>
function saving()
{
}
</script>
</html>

Now I want to save text from mytext to text-file file, say mytext.txt. All data/files are accessed locally on my PC. So, How can I do that? With PHP or JavaScript?; then How? (give me some basic script/information).


Also Suggest me external resource for learning interaction html form with database.

I am using Trisquel 7.0. I've some basic knowledge about html and JavaScript. Now I want to save html form data to file (Also interested in loading/filling html form from file).

I searched and found that This would be possible with php etc. But I don't know How to. As a beginner at this time, I would like to save only text information in text-file simply from html form.

Below I am writing simple example with simple html form and JavaScript function (without any action)

<html>
<form name=myform>
<input type=text name=mytext>
<input type=button value=save onClick=saving()>
</form>
<script>
function saving()
{
}
</script>
</html>

Now I want to save text from mytext to text-file file, say mytext.txt. All data/files are accessed locally on my PC. So, How can I do that? With PHP or JavaScript?; then How? (give me some basic script/information).


Also Suggest me external resource for learning interaction html form with database.

Share Improve this question edited Jan 26, 2015 at 7:27 Pandya asked Jan 26, 2015 at 7:18 PandyaPandya 1982 gold badges4 silver badges19 bronze badges 6
  • Do you want to store the Data serverside (with PHP) or Clientside (with Javascript)? And for what reason? Maybe Cookies are an better Idea (Cookies are also just Text Files, but easier to access) – j_s_stack Commented Jan 26, 2015 at 7:20
  • @j_s_stack At this time I want to save data to my PC locally. (probably Client-side) – Pandya Commented Jan 26, 2015 at 7:22
  • Have a look here: w3schools./js/js_cookies.asp – j_s_stack Commented Jan 26, 2015 at 7:29
  • Here it tells you how to use it to save Form Data: the-art-of-web./javascript/setcookie – j_s_stack Commented Jan 26, 2015 at 7:31
  • 1 PHP would also be the better solution if you want to upgrade to an Database Version later on. – j_s_stack Commented Jan 26, 2015 at 7:41
 |  Show 1 more ment

2 Answers 2

Reset to default 8

If you want to save the form data on the server side, I would do it with php like this:

<?php
$action = $_GET["action"];
$myText = $_POST["mytext"];

if($action = "save") {
  $targetFolder = "/path/to/folder";
  file_put_contents($targetFolder."mytext.txt", $myText);
}
?>   
<html>
<head>
 <title>myform</title>
</head>
<body>
  <form action="?action=save" name="myform" method="post">
    <input type=text name="mytext">
    <input type="submit" value="save">
  </form>
</body>
</html>
  • The file itself needs to be a php file.
  • There is no form-validation implemented in this example
  • The webserver needs write permissions in $targetFolder

However if you want to save the data on the client side, normally you do it with local storage. But mind that only the client can access data of his local storage. Here is an example: Storing Objects in HTML5 localStorage

To save data without database or backend, you can services that provide just that. 1. PageClip 2. Usebasin 3. FormKeep 4. netlify 5. Formcarry

Follow this blog link to see details http://rohitvinay./how-to-store-contact-form-data-without-backend/

发布评论

评论列表(0)

  1. 暂无评论