6

Is it necessarily required that the action="abc.php" in FORM tag must have a PHP, JSP, ASP file? Can't simple HTML code display the data submitted in the FORM?

In other words,

FILE: abc.html

<form method="post" action="xyz.html">
     <input type="text" name="name" id="name" value="Enter your name here" />
</form>

OR

<form method="get" action="xyz.html">
         <input type="text" name="name" id="name" value="Enter your name here" />
</form>

Now in file xyz.html, can I display the name entered in abc.html using only HTML code?

sumit
  • 10,935
  • 24
  • 65
  • 83
  • 3
    No you can't, you'll need a serverside language to get the values posted to the server. – adeneo Dec 21 '12 at 08:14
  • 1
    @adeneo I don't totally agree... In case of **GET** parameters, that can be read with client side code too. Not plain HTML though, but basic JavaScript can do that... Check this question: [Use the get parameter of the url in javascript](http://stackoverflow.com/questions/827368/use-the-get-parameter-of-the-url-in-javascript) Of course, in case of **POST** parameters your argument is true... OP wasn't entirely clear on this, as the title says GET too... – ppeterka Dec 21 '12 at 08:16
  • @ppeterka - agreed, you can get the URI from the browser and extract the different values from the querystring, but that would require javascript, and there's really no advantage to that over just using something like PHP to print the values with a simple function call. – adeneo Dec 21 '12 at 08:19
  • @adeneo I agree to you - by the way, who uses plain HTML these days to actually _do_ something without server side code? The only use case I can think of is some sort of (self) learning situation, when one needs to learn the limitations/unique features of client side approaches... – ppeterka Dec 21 '12 at 08:21

7 Answers7

5

HTML by itself can't access submitted POST/GET data. You need a server side language (PHP, python, ruby, .NET, ...) to put those values into HTML.

That being said, you can post to a HTML page, you just won't be able to do anything with it.

You could use JavaScript to access GET variables, but not POST.

Community
  • 1
  • 1
Jan Hančič
  • 53,269
  • 16
  • 95
  • 99
3

You cannot dispaly it using html only. You need to have a server side scripting language like PHP,ASP.Net or java etc...

웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
2

The purpose of using those server side extension is to manipulate the data sent from the form elments on the server with the method of POST or GET, but if you only want to show the data entered on the browser, you can send it to the .html file because they do not need to be manipulated at all.

Tepken Vannkorn
  • 9,648
  • 14
  • 61
  • 86
2

No, you can't. Cause the post data transfer to the server, and the server can't deal with the data with simple HTML code except a server language like PHP, PYTHON, JAVA etc.

Levin
  • 194
  • 5
2

you need a server side language in order to process the form and grab the data from the user. In PHP, at least, as I know you can leave the action="" empty which means you will process the form on the same page

ltdev
  • 4,037
  • 20
  • 69
  • 129
0

Yes, you could do it with plain html + javascript. As an example you can retrieve http parameters by using jQuery. More information available here:

Get escaped URL parameter

Community
  • 1
  • 1
jap1968
  • 7,747
  • 1
  • 30
  • 37
  • I assume that means he does not have a server to run some scripting language such as PHP, ASP and so. The simplest httpd server can serve plain html and plain javascript. – jap1968 Dec 21 '12 at 08:19
0

You can do it using jQuery Ajax method.


$(document).ready(function(){
          ajaxFunction();
});
    function ajaxFunction() {
        var postdata = jQuery("#form").serialize();
        jQuery.ajax({
            url: "xyz.html",
            type: "POST",
            data: postdata,
            success: function(response){
                    console.log(response);
            },
            error: function(){
                console.log(response);
            }
        });
    } 

reference

Surinder ツ
  • 1,778
  • 3
  • 16
  • 27