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!
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
Shamez Walji6,602 Points
How to add functionality to HTML forms
Hello so I am completing the HTML forms module and I have successfully applied a contact form to my personal website. However, it does not do anything when I hit submit. I was wondering how would I go about making the contact form work? What would be the next treehouse modules to learn from?
- HTML = Content
- CSS = Presentation
Don't worry, treehouse has you covered ;)
I can't belive there hasn't been a defacto answer to your original question yet. Here is the course you need:
DOM Scripting by Example
Shamez Walji6,602 Points
Sergio Alen26,726 Points
I think your explanation is excellent huckleberry.
But I'm guessing what Shamez is asking is more specific to a "Contact" form as forms can be for anything e.i. login forms, newsletter forms, etc. For contact forms the most common action is to send an email confirmation to the admin of the site, so for that I'd say jump onto PHP lessons.
What about the 'mailto' function? Could this be used for a simple contact form, before one has learned any server-side scripting?
Byron Glover5,772 Points
Thanks for all the great info so far, is it possible to submit the form to an email address like email@example.com with out requiring some fancy back end code?
Well, the thing is, 'submission' is already built in to the browser and the submit button is specifically built to tell the browser "ok, send this info somewhere!" and then the page refreshes... So, it's not the languages that allow you to 'submit' but rather the languages that allows you to build a script, have it on your server, and then use that script name to tell the browser WHAT to do with that information that's being 'submitted'. i.e. what script to send that stuff to.
Like, ok, you have a form and you've built it with several input fields and a submit button. You type stuff in and you hit submit. POOF! The page refreshes and it's all gone. It did go through the submit action it just didn't send it anywhere and it went nowhere and got discarded.
What you're thinking of with the PHP, Python, etc... is the script on the server side that you would send it to. And the answer is... any of those. You could have a PHP script a python script a perl script and now, you can use node.js for all that too.
When you have a form, you have those attributes of action and method, right? Well the method says what kind of submit you're rockin' (post/get) and the action tells the browser where to go to post OR get the information.
So, your options are wide open as far as what you can actually use, it just depends on what you have running on your server that you're trying to communicate with.
But as far as the actual submission, that's just handled by the button/browser by default. What happens to the data after you hit submit, that's where you're using the server side scripts as a destination in the ~action~ attribute
p.s. If anyone wiser and more experienced with this stuff sees some incorrect info in the above, please, by all means, correct it.