Form Data will not post to csv file

Issues related to forms.
Post Reply
gmaclean482
 
 
Posts: 4
Joined: Thu Aug 09, 2018 11:37 pm

Form Data will not post to csv file

Post by gmaclean482 »

I will admit to being a novice here, but I have run out of places to troubleshoot, and a search of this site does not reveal anything helpful here (apologies if I missed a topic this is addressed.)

I added a very simple three Editbox form with a Submit button to a new page on an existing site, all built with Wysiwyg.

I used the Form Wizard to set things up, including the addition of a .csv file to record the data entered so that I can retrieve that information and manipulate it in Excel on my personal computer (it will be a registration form eventually.)

The page displays. The edit boxes receive the information. The success page displays. An email is sent out containing the data entered. But nothing goes to the .csv file. Its empty, and stays empty.

I have double and triple checked the read/write permissions of the .csv file and the location was set when the file was created by the Form Wizard, and my hosting site supports PHP (v7.0.33). The page is PHP enabled.

The events "onsubmit:Form Submit:self" and "onsubmit:Form Reset:self" are Form Properties.

These are all just starting points for what I want to do (add) to the form later. But I want to get past this hurdle of why the data is not writing to the .csv before I continue.

Any ideas?
Last edited by gmaclean482 on Thu Feb 27, 2020 3:35 pm, edited 1 time in total.
User avatar
Pablo
 
Posts: 21578
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Form Data will not post to csv file

Post by Pablo »

The only reason I can think why this can fail is when the cvs is not accessible/writable.
Are there any errors in PHP error log on the server?
gmaclean482
 
 
Posts: 4
Joined: Thu Aug 09, 2018 11:37 pm

Re: Form Data will not post to csv file

Post by gmaclean482 »

OK, I will amend my previous post.

IF I turn off the csv file write I get the email (I forgot that I did that last night). Everything in my previous post is based on that configuration, including the display of the success.html file.

When I turn the csv file write on and click "Submit" I get a "can't open file" error.

This is the error I get in the log:

[27-Feb-2020 16:24:41 UTC] PHP Warning: fopen(./public_html/Athlete_Data/formdata.csv): failed to open stream: No such file or directory in /home/churchc1/public_html/TestBed.php on line 59

The page is named "TestBed.php"

Line 59 of the page code is:
$handle = fopen($csvFile, 'a') or die("can't open file");

Earlier in the page code:
$success_url = './Success.html';
$error_url = './Failure.html';
$csvFile = "./formdata.csv";

and again, in the host site directory the csv file is in,

./public_html/Athlete_Data/formdata.csv

and is present, and the file formdata.csv was created via the Form Wizard.

It really seems that the Form Wizard created the file, but instructed the code to look for the .csv file in "testbed.php" rather than in the proper directory. Should I edit the .php file by hand? and will this happen with any other .csv links I create? Also, I note double quotes around the filename reference in the $csvFile = line above, I dont know if that makes a difference.
User avatar
Pablo
 
Posts: 21578
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Form Data will not post to csv file

Post by Pablo »

This error indicates that either the file does not exist or the file / folder is not writable.

You do not have to edit the code. If the path is not valid then you can set the correct path in the properties of the form.
gmaclean482
 
 
Posts: 4
Joined: Thu Aug 09, 2018 11:37 pm

Re: Form Data will not post to csv file

Post by gmaclean482 »

The file is now correct in the PHP file

$success_url = './Success.html';
$error_url = './Failure.html';
$csvFile = "./public_html/Athlete_Data/formdata.csv";

I have cleared any cached pages to make sure that I am getting the current version, and I still get the "can't open file" error from line 59 (previous post). The error log is as follows:

[27-Feb-2020 18:35:20 UTC] PHP Warning: fopen(./public_html/Athlete_Data/formdata.csv): failed to open stream: No such file or directory in /home/churchc1/public_html/TestBed.php on line 59

It STILL looks like the PHP code is trying to open the right file ./public_html/Athlete_Data/formdata.csv but not looking in the right location /home/churchc1/public_html/TestBed.php
gmaclean482
 
 
Posts: 4
Joined: Thu Aug 09, 2018 11:37 pm

Re: Form Data will not post to csv file

Post by gmaclean482 »

OK, another troubleshooting point, should there be anything in the Submit button properties regarding Link:File or URL parameters for internal links?
User avatar
Pablo
 
Posts: 21578
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Form Data will not post to csv file

Post by Pablo »

Either the path in the form properties is incorrect.
or the file does not is the specified folder.

The problem is unrelated to URL parameters.
CNS
 
 
Posts: 6
Joined: Sat Apr 18, 2020 7:42 am

Re: Form Data will not post to csv file

Post by CNS »

I have a similar problem in saving form data to a csv file
If I upload all my site pages to the public_html dir and create the data file via the form/properties/advanced where the new file is set to ./awwwwdata.csv the file is put into the root dir but data is saved to a file in the public_html dir (if the file is already there). If not, the file is created at run time and data entered
If I create the file as ./public_html then the browser throws up the "can't open file" message. The datafile permissions are set to 0644 or 0666
I can save create a new file any where on my server at design time,
thus /public_html/SQH/awwwwdata.csv is the path and the csv data is created in the correct dir but "can't open file" appears
if I create this file ./SQH/awwwwdata.csv which I can do by having another root subdirectory, then the file is created in ./SQH and data is correctly saved to it

If I upload all my web files to ./SQH/ then again files are created but data writing to then fails irrespected of where the data directory is created.

An easy easly solution to this problem might be to make the file path below the server directory tree editable
Thanks Norman
User avatar
Pablo
 
Posts: 21578
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Form Data will not post to csv file

Post by Pablo »

If no data is written to the file then either the location of the file is incorrect or the permissions are not valid.
Hbrownell
 
 
Posts: 143
Joined: Fri Dec 06, 2019 3:58 pm
Location: Kentucky
Contact:

Re: Form Data will not post to csv file

Post by Hbrownell »

How do I properly set permissions at what level? I have a public_html/website.com/site.html format. Where and how do I set permissions so that I can write to the csv?
User avatar
Pablo
 
Posts: 21578
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Form Data will not post to csv file

Post by Pablo »

You will need to set the permissions of the CVS file on th server. For example, via FileZilla.
Hbrownell
 
 
Posts: 143
Joined: Fri Dec 06, 2019 3:58 pm
Location: Kentucky
Contact:

Re: Form Data will not post to csv file

Post by Hbrownell »

Right, but my question would be at what level do I need to do this? IE at the website root folder? website.com, the public_html? And then, what should the setting be so that the form can make changes? I don't think having 777 would be appropriate or safe. Is there another credential somewhere I should have set so that the form can make modifications (making it a user basically)? <--guessing here. :P
User avatar
Pablo
 
Posts: 21578
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Form Data will not post to csv file

Post by Pablo »

You can first try 666, if that does not work then use 777.
As long as the file is writable, it's OK.
Hbrownell
 
 
Posts: 143
Joined: Fri Dec 06, 2019 3:58 pm
Location: Kentucky
Contact:

Re: Form Data will not post to csv file

Post by Hbrownell »

And where would I apply this to? The file, or does the folder need the setting?
User avatar
BaconFries
 
 
Posts: 5328
Joined: Thu Aug 16, 2007 7:32 pm

Re: Form Data will not post to csv file

Post by BaconFries »

And where would I apply this to? The file, or does the folder need the setting?
You apply the permission to the file itself. You also need to ensure the path to the folder / file is correct such as the following public_html/your folder/nameof.csv As Pablo you can use the likes of FileZilla to set this or you can set via the server using cPanel.
wwonderfull
 
 
Posts: 1255
Joined: Fri Aug 21, 2020 8:27 am

Re: Form Data will not post to csv file

Post by wwonderfull »

I do not have any problem with the csv. I still use it. the problem may be that when you go to form advanced and then check on csv it wants you to name a .formdata.csv you save and publish it in public_html or on other cases htdocs ftp directory directly, the csv file name has to be the same as published and can not be in sub folders. if the email comes to you good then be sure that form data also comes for sure.
Post Reply