I have multiply signup forms across my website that POST to a php file(code below) then are saved to a txt file. I would like if I could get all the forms to save to the same/one txt file
Provided you open the same file in append mode each time, then yes, you can have as many forms across your site as you like all saving data into a single text file. You may want to separate the values on each line by a comma though (since people may enter phone numbers with spaces in between). I’d also validate the data being submitted before just blindly entering it into your text file (since at the moment, empty forms can be submitted along with newline characters that will wreck the file formatting).
I have about three directories that have signup forms that save into it’s own .txt file in each directory. Since I manually have to go through that data it would be easier if I could access it from one .txt file. I have tried changing the mode for fopen()
Here is an example of how the information submited is saved to the .txt file.
John Doe johntest@doetest.com January 12345
Jane Doe janetest@doetest.com March 12345
You’ll want to change the path of fopen() for each form to point to a single file too. If you’re having trouble doing this, then post your directory setup here along with the location of where those three forms reside.
Right, but what if someone enters a space? Your formatting would become messed up. Like I said in my original post, I’d personally separate the values by commas and write that to a file - this will form a comma-separated values (CSV) file. PHP has a built-in function for this already to make things easier for you, and you can make use of it by simply changing these lines:
Here is my directory set up: domain.com
-Counter Sign Up
-index.html
-save.php
-countersignup.txt
-Newsletter
-index.html
-save.php
-npgrnewsletter.txt
-Newsletter Home
-index.html
-save.php
-homepagenewsletter.txt
Each .php file saves to the .txt file in that directory.
So how are you distinguishing the data between each of the three forms? If the data for all three forms are being saved to a single text file, then how will you know which data in the text file belongs to which form?
In any case, to get all three forms to save to a single text file, place a text file outside of all three sub directories:
domain.com
global.txt
-Counter Sign Up
-index.html
-save.php
-Newsletter
-index.html
-save.php
-Newsletter Home
-index.html
-save.php
and change the file path in all three fopen() functions for each form to:
I don’t believe fopen() can modify files on remote websites. You could, however, use CURL to send an HTTP POST request from site y.com (on form submission) to site x.com, where site x.com saves this incoming POST data to the text file specified. You will need to verify that this POST data is coming from a known source (perhaps by sending a key along with the POST data to verify the sender as known).
He means persisting the form data in a DBMS (like MySQL), rather than using text files to store the data.