0

Take, for example:

<form action="/action_page.php" method="get">
#Code here...
</form>

The action attribute results in a submit sending the form data to a PHP file called action_page.php.

Is it possible to refer it to an HTML file instead?

Like, maybe:

<form action="/action_page.html" method="get">
#Code here...
</form>

I realize that this may be too simple a question. But I really just want to know if it is possible.

It not, is there any other way to send form data from HTML file #1 to HTML file #2 so that I may make use of the data from file #1 in file #2?

Note:

I don't want to manipulate my HTML file to run or function as a PHP file unless it is the best way to be able to transfer form data from one HTML file to another.

robinCTS
  • 5,746
  • 14
  • 30
  • 37
Kennoob
  • 3
  • 2
  • For passing data from html page to other you can use query parameters, You can also store it in local storage and read it in second page. – Mike Ezzati Mar 04 '18 at 00:29
  • Indeed this question is not a duplicate of [Using .htaccess to make all .html pages to run as .php files?](https://stackoverflow.com/questions/4687208/) – RandomSeed Mar 05 '18 at 10:23
  • The formal answer to your question is: yes, you can send the form dat to a .html location but either 1. the target is a plain HTML file and the data will be ignored or 2. you manage somehow to process the query from the HTTP server itself by 2.a. mapping the .html extension to some server-side scripting language (be it PHP or anything else, e.g. bash) or 2.b. use a HTTP server that provides such a feature (such as Node.js) – RandomSeed Mar 05 '18 at 10:27

1 Answers1

0

The action has to point to a URL.

If you make a POST request, then the submitted data will be available only to server-side code (browser-side JavaScript cannot access it).

HTML is not a programming language. It cannot do anything with a POST request. Server-side code can dynamically generate HTML as its output though.

The server-side code can be written in PHP. It does not have to be. You can use any programming language you like.

If you use PHP, then you do not have to have .php in the URL but that is the simplest way to configure a server to run a PHP program to generate the response to a request for a particular URL.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • I already almost forgot about this question because it was closed due to duplication. I'm actually still pretty much new to web programming. What I did during the time this was closed was that I made those **HTML** files into **PHP** files. I did not have the time to wait because it was for a homework due the next day. – Kennoob Mar 07 '18 at 13:59
  • Nonetheless, thank you. You made me understand stuff I couldn't and you definitely answered my question – Kennoob Mar 07 '18 at 14:01