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

General Discussion

Sending a form (back-end) using javascript

I am retraining and currently on the javascript track as I understood javascript was a good place to start learning.

A friend asked me to look at setting up a form on their website and it looks like I will have to switch to php in order to get it working back-end i.e. submit actually sends the form.

Is this the case or is sending a form using javascript on the back-end covered here at treehouse and if so, please could you show me where that might be.

4 Answers

Fundamentally JavaScript is not meant or designed to be a backend work horse language. It was/is designed to help animate and create dynamic content on the front-end (where it actually runs. Unlike php or python or java 100% of javascript is run client side in the browser....and that statement is true...99% of the time!) and is considered just that, a front-end language.

JavaScript would not process your form, it would make sure all the fields were filled out and filled out with the right information. Something like PHP or Python or Java would do the heavy lifting on the backend to actually process your request.

But that being said we humans love evolving so you can look at something like node.js if you specifically want javascript on the back end (the 1% exception from above :) ).

hope that helps!

Just realized that you probably already know all of that about javascript so I be misunderstanding what you are asking!

I will try to answer it again.

Server side JavaScript is Node.js and here is the link to the beginning course Node.js

I hope one of those answers helps! :D

Thanks for the speedy reply Shawn.

I was going to attempt to learn how to send a form with node.js with the possible help of express, but I wasn't sure such a thing was even possible...I suppose that is the question: is it possible??

I have never done it...a bit out of the box for me. But I don't see any reason why not.

What are you wanting to do with the form? Write to a DB?

The form is a simple contact form.

To clarify/explain a bit:

I wanted to use the knowledge I already had the most of (javascript) to do it and I am a bit worried about overloading my brain with too many languages/technologies at this early stage. I wanted to get to grips with one language/technology, then move on, in time.

I didn't want to waste time on it if it was impossible though! :)

Gotcha!

well I found this about hooking up node.js to a MySQL Database so that pretty much answers it! I think you are good to go !

https://codeforgeek.com/2015/01/nodejs-mysql-tutorial/

thanks!