PHP Form Recs?

Hello! I’m building a form (very beginner and very basic) and am struggling with being able to collect and see the data. I tried my best following some php tutorials but I’m thinking of biting the bullet and going third party. I didn’t see any recs though in the resource list.

Are third party sites not recommended? Or are there any good ones yall suggest? If not recommended any resources to help me figure out php?

My PHP days are far behind me. Dunno where is a good place to start learning the language nowadays. I just peck at the official documentation when I have to. (That includes a tutorial, by the way.) How far along into PHP are you? What’s giving you trouble?

Are you on the Neocities free tier? That might be blocking you from collecting form data, if that’s where the form is hosted.

Here’s the code to my guestbook - it’s basically a simple PHP form that writes data to a textfile and then displays it on the page. You’re free to take and adapt it - though as others have said, no PHP on Neocities so I hope you’ve got another place to experiment.

1 Like

I am paid so thankfully that’s not the issue.. it’s more like I dont understand how my data collected from forms gets stored and where I can see it

So I have a collection form that i want to stay private where I can see the info but no one else can. I have a form built… but the struggle is where do I collect the data and how do I view it and amke sure no one else can see

I may have actually seen your site from the no ai webring before! Nice to see your page again :slight_smile: My issue is that I want the form to hold the info privately so I can moderate it before sharing it… am I am able to create that setting with yoru template?

In a database somewhere, or at least a CSV file. Frankly I recommend using some sort of hosted solution, like the forms app in CryptPad.

Hey @gelseyland! I’m working on a small online book thing called PHP For People (inspired by Blake Watson’s excellent HTML For People), and this is the exact thing that the book will cover: the ins-and-outs of form submission and data processing/storage/retrieval (from flatfiles, so no complex and intimidating database stuff). It’ll walk you through every aspect of the process of building a simple guestbook app (which is pretty much entirely about submitting data with a form and then showing it somewhere else!). So hopefully it’ll be helpful to you and others trying to do this kind of stuff!

But, until that’s ready, I’m more than happy to help you out with this if you want to hang in there with building your own!

The answer to the question of where the data gets stored is pretty much “where you tell it to” :grinning_face_with_smiling_eyes: which probably doesn’t help much in general, but more specifically the function file_put_contents is how this is usually done. It takes two required arguments, the first being the path (with filename) where you want to save your data, and the second being the data itself.

So, for instance, let’s say you want to store your data (which we’ll say lives in a $data variable for this example) in /home/gelseyland/www/private/data.txt. You’d do this:

<?php
file_put_contents('/home/gelseyland/www/private/data.txt', $data);
?>

And that’s where your data will be saved.

Now, the other part about keeping the data secure — that’s important, and how it’s done depends on your web host. Most web hosts have a “public” directory which serves as the web root, which is where all of your HTML is served from and your PHP scripts are accessed and such. The easiest way to keep your submitted data secure is to not store it in that public web root. Instead, save it to a location outside of it, and then no prying eyes will be able to access it by guessing filenames in their browser.

With your data saved outside of the web root, you can then ensure that the only way people see it would be from a script that you control (in the web root). The script would open the file, read the data, and control what’s shown and how.

If you’d like a super basic example of a form, a PHP script that receives the data and saves it, and another PHP script that opens the data and displays it, I’d be happy to whip something up. :+1:

In that case, maybe you’d want to play around with my my webring code - someone submits the form and their data is added to a textfile that is set to be inaccessible to users. You get an email with the data, including a link to add the data to a JSON file, the contents of which are then reproduced on the page. You can also set that JSON to be unviewable to users, of course.

It comes with a lot of extra bells and whistles, but you can strip those out, or just take the bits you like and create a new thing from them.