Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Ryan Hemrick
12,759 PointsCollecting form data from users
Hey everyone,
I am in the final stages of creating my portfolio website and the final step is to find a way to gather the information users enter into the form.
The form is rather basic, just an input field for Name and Email, and a textarea for a Message. I really don't know what my options are when collecting data from users. Do I have to use a database for handling the data, can I just get the submissions emailed to me, and do I need to use a serverside language?
I am looking to hear what my options are for accomplishing this. Any help is appreciated!
Thanks!
2 Answers
Erik McClintock
45,783 PointsRyan,
You could use a database, or you could have the information emailed to you via a standard contact form. The Build a Simple PHP Application course here on Treehouse (and its sister course that comes after it, Enhancing a Simple PHP Application) will help you learn a bit about the language and how to get going with sending and receiving emails using PHP.
If you'd rather go the database route, the Using PHP with MySQL course is a good place to go.
There may still be a bit more to learn afterward, and some specifics to work out with your hosting service, but this is a great place to start!
Erik
Giorgi Gelashvili
1,504 PointsI agree with Erik, you could use PHP/MySQL to store & retrieve data. Just to add to that:
Make sure you filter all user input & never trust what user submits via form field. It could be SQL Injection or XSS.
You might also want to filter these even if you decide not to use database and have information being emailed it to you.
Erik McClintock
45,783 PointsYes, you will definitely want to make sure you scrub your user input! Always a good practice.
Good note, Giorgi.
Erik
Ryan Hemrick
12,759 PointsRyan Hemrick
12,759 PointsThanks for the response Erik!
I just started the Build a Simple PHP Application course. Glad to see I was on the right track! With information from users only coming through three input fields in one form, would you see the emailed contact form as an easier to manage option? On larger projects I could see where a database would help, but I feel as though it may be a little overkill for a portfolio contact form.
Thanks!
Erik McClintock
45,783 PointsErik McClintock
45,783 PointsRyan,
If you don't need to keep a nice record of the people that contact you, then yes, I would think an email submission should be more than sufficient!
Happy coding!
Erik