Hold on to your horses 🐎, because now we're going to discuss one of the most important attributes there...
is on the form element, and that is, the "action" attribute. Basically is just a URI, just a location, indicating...
where the script is responsible for the manipulation of the data sent by the form.
That's all good and well, but what does it look like?
Well, here we go.
Here we've set the action attribute to the process_url. And that process_url is just where the form data...
is going to be sent to.
I'm sure you can really see that the action attribute is therefore crucial.
It's basically the browser asking you the question "where do you want all the data in the form sent to?" That is a...
very good question.
And if you specify nothing, it really won't get sent anywhere.
Well in fact, it actually, it's just sent to the current page you're on, which we're going to see shortly.
But as you know, the old adage, "pictures are worth a thousand words".
So let me just draw something up for you quickly.
Let's say we have a web application with a very simple form on it, with a "Register
Now" button, when the user fills in all this information and when the form is eventually submitted,
aka. when the user clicks on the Register
Now button, then your browser is going to gather that form data, and it's going to have to send that form...
somewhere.
It's going to have to send it to a server.
But where exactly...
should your browser send it, because your server could be quite large with many files and scripts handling...
different URIs.
And this is exactly where the action attribute comes into the picture.
It tells your browser exactly where to send that form data to your server.
What happens next?
Well, your server will then pass the form submission data to the form processor script.
And that script is written in languages like, I don't know, PHP, Python, Node, Perl, etc etc.
FYI, we're going to see some cool examples later in this course of actually using backend server code...
although it is very advanced and it's not the scope of this course, but I just love it 🥰.
So I will show you how that works later.
Just remember that the form script can validate the form, it can save the data to a database or a file...
and it can perform a whole bunch more.
So, for example, if your action attribute was set to, I don't know, a login URI, maybe your...
form on the backend could verify the username and password of a user...
and if successful, your server could redirect that user to a logged in version of a webpage.
And I don't know, the cherry 🍒 on the top could be a nice welcome message.
(sound effect: mission completed) Is that starting to sink in?
Can you see how important the action attribute is?
As a very quick summary...
just remember that the action attribute tells your browser exactly where to send the data.
And a common technique is to send the data to the same page the form is on.
In fact, this is the default scenario...
when you don't specify an action attribute at all. Let's just quickly look at one more example before...
I finish off this lecture.
Let's just say the action attribute doesn't even specify a URL.
It just gives a file name.
Well, in this instance, when the submit button is pressed, it will send the form data to the script...
on the same URL, to the "process.php" script in this example 😵.
Don't worry if you don't know exactly how this works or how the server will manipulate the data.
That's not the point of this lecture.
The point of this lecture was just to get you familiar with why that action attribute is so important.
So take a breath.
You've learnt a lot, and let's keep going.
I want us to discuss another incredibly powerful attribute on the <form> element in the next lecture.