0

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?

user1301428
  • 1,743
  • 3
  • 25
  • 57
  • Not sure what you mean. How would that other file be called? – Pekka Jun 21 '12 at 08:44
  • @Pekka I don't know, I think it wouldn't matter. 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. – user1301428 Jun 21 '12 at 08:51
  • Did you know [JS can parse GET parameters](http://stackoverflow.com/questions/9048360/how-to-extract-relative-url-from-argument-values-from-request-string/9048444#9048444)? – Shiplu Mokaddim Jun 21 '12 at 09:10

5 Answers5

1

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.

Bas Slagter
  • 9,831
  • 7
  • 47
  • 78
1

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.

Curtis
  • 101,612
  • 66
  • 270
  • 352
  • So the data would be processed by, let's say, the PHP code contained in Page2.html, even if I am not explicitly saying that the data should be processed by this PHP code? – user1301428 Jun 21 '12 at 08:59
  • @user1301428 What I'm proposing is that you do exactly what you would normally do with a HTTP POST, but then redirecting to a 3rd page after the process has been completed. – Curtis Jun 21 '12 at 09:47
  • Is there a way in which I can check if the data has actually been processed during these steps and that it's not a simple redirect? – user1301428 Jun 22 '12 at 18:35
  • Is it possible to do this even if I don't have access to the files on the server? – user1301428 Jul 09 '12 at 20:04
1

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.

Community
  • 1
  • 1
Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187
1

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.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
0

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.

Jezen Thomas
  • 13,619
  • 6
  • 53
  • 91