Save form in txt file

Asked

Viewed 845 times

-1

It is possible to save a form in TXT file?

I will explain... I have a site for data protection like NAME and EMAIL, only.

I would like to save in TXT every new insertion. So:

1| Fulano - [email protected]
2| Sicrano - sicrano @site.com.br
3| Baltrano - baltrano @site.com.br
.
.
.

Thank you.

  • Yes it is possible, you can see how it works to read and create files in your programming language, with this, just create the function or method that will be sent the post form, is there you create your file in the desired format. I don’t use php anymore it shouldn’t be difficult to create files there.

  • 1

    Look: https://stackoverflow.com/questions/34641015/really-simple-php-form-to-save-to-a-text-file

1 answer

0

Hello, you can use this with the example of the code below (in PHP).

<form action="myprocessingscript.php" method="POST">
<input name="field1" type="text" />
<input name="field2" type="text" />
<input type="submit" name="submit" value="Save Data">
</form>

<?php
if(isset($_POST['field1']) && isset($_POST['field2'])) {
    $data = $_POST['field1'] . '-' . $_POST['field2'] . "\n";
    $ret = file_put_contents('/tmp/mydata.txt', $data, FILE_APPEND | LOCK_EX);
    if($ret === false) {
        die('There was an error writing this file');
    }
    else {
        echo "$ret bytes written to file";
    }
}
else {
   die('no post data to process');
}

Ideally you use a database for data recording, you can use Firebase Realtime Database for this process, the implementation method is super simple and you find a lot of "ready" material in Github.

Or, if you prefer, you can use an API that provides open source on Github to use as "Getting Started" in projects: https://github.com/andersoonluan/graphql-nodejs-api

A hug and good luck!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.