Reputation: 1783
I know, this sounds like a weird question, I will try to explain this more clearly. I know that the file included in the action
attribute of a form element is the location of the file that will process the data entered in the form.
Now, does it make any sense to have an HTML file in the action
attribute and let the data be processed by another file? Is this possible?
Upvotes: 0
Views: 616
Reputation: 449395
It's just that I've seen a couple of forms with an html file in the action attribute, so I was wondering if the data could be processed in another place.
It probably was a static HTML file by name only. A URL is not a reliable indicator of what kind of file is behind it. The form target was probably a server-side script "hidden" behind a .html extension that processed the data.
Upvotes: 1
Reputation: 57650
Its useless as HTML file alone can not process all the parts of a HTTP request. HTML can not parse data in header and body. And there is no other place where data is passed. So HTML can not process passed data.
But first, make sure those links with .html
extension are really html file. Not server side script hidden in .html
extension!
Note. Javascript can parse parts of GET parameters! See this answer. It shows how Javascript can parse GET data. So you can create an application with just using GET method on forms and plain JS to parse it.
Upvotes: 1
Reputation: 13800
If you want to send the data somewhere other than the file you call in the action
attribute, I imagine you would probably do that with JavaScript. That being the case, you may as well use JavaScript to send the user to the new HTML page too.
The other answers to this question are valid and they work, but the whole idea in itself is a bit pointless. So my answer is:
Yes.
It's useless.
Upvotes: 0
Reputation: 103348
The action
attribute is where the HTTP POST request is sent to with the form data supplied.
It is then up to the action
URL page to process this data and do whatever it needs to with it.
If you wish to process the data on one file, and redirect to another, you could post to the HTML which will process the data, and then have an automatic redirect on that page to a 3rd page.
For example:
Page1.html:
<form action="Page2.html">
Page2.html:
Processes data then automatically redirects in some way:
<script type="text/javascript">
window.location = "Page3.html";
</script>
Page3.html:
Finally arrive at Page 3.
To the user this process would be seemless and appear as if they went from Page1.html
straight to Page3.html
, while your data processing is handled at Page2.html
.
Upvotes: 1
Reputation: 9929
Yes, this is possible. You can, for example, include another file in the file you are pointing to from the action attribute of your form. But since you want that to be an HTML file, you are stuck (you cannot include HTML files into each other). But...if you want to process the form, you probably want some server side code to be executed which would be something like PHP or ASP. Than you have to options. 1. point to an PHP file instead of an HTML file or use some url rewrite (through some .htacess file or something) to redirect the html file to your server side scriping file.
Upvotes: 1