Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST from an <A> tag

Tags:

html

post

Is it possible to do a POST from just an <a> tag? I know anchor tags are usually just for GETs, and I know I can use javascript to do this (like in JavaScript post request like a form submit) but to me that seems a little messy. Is there a way to do this with straight HTML?

like image 814
Carrotman42 Avatar asked May 30 '11 19:05

Carrotman42


People also ask

Can an A tag POST?

There is no way to POST an a element using only HTML. There is no attribute that controls whether to use POST or GET with an a element. You have to script it, if you want to abuse the semantics.

What is the use of POST tag in HTML?

POST is used to send data to a server to create/update a resource. Some notes on POST requests: POST requests are never cached.

How can I submit a POST form using the A HREF tag?

You can use href=”#top” or href=”#” to link to the top of the current page. To use the anchor tag as submit button, we need the help of JavaScript. To submit the form, we use JavaScript . submit() function.

Which type of HTTP request will an A tag trigger?

<input formaction=url> <source src=url>


2 Answers

Not really, no. You can, however, do something like this:

<form action="theUrl" method="POST">  <input type="hidden" name="param1" value="val" /> <input type="hidden" name="param2" value="val2" />  <a href="#" onclick="this.parentNode.submit()">Go to that link!</a>  </form> 

You should find a better way, though. This one does not degrade gracefully.

like image 154
Ry- Avatar answered Oct 09 '22 01:10

Ry-


There is no way to POST an a element using only HTML.

As can be seen from this DTD fragment (HTML 4.01 spec):

<!ELEMENT A - - (%inline;)* -(A)       -- anchor --> <!ATTLIST A   %attrs;                              -- %coreattrs, %i18n, %events --   charset     %Charset;      #IMPLIED  -- char encoding of linked resource --   type        %ContentType;  #IMPLIED  -- advisory content type --   name        CDATA          #IMPLIED  -- named link end --   href        %URI;          #IMPLIED  -- URI for linked resource --   hreflang    %LanguageCode; #IMPLIED  -- language code --   rel         %LinkTypes;    #IMPLIED  -- forward link types --   rev         %LinkTypes;    #IMPLIED  -- reverse link types --   accesskey   %Character;    #IMPLIED  -- accessibility key character --   shape       %Shape;        rect      -- for use with client-side image maps --   coords      %Coords;       #IMPLIED  -- for use with client-side image maps --   tabindex    NUMBER         #IMPLIED  -- position in tabbing order --   onfocus     %Script;       #IMPLIED  -- the element got the focus --   onblur      %Script;       #IMPLIED  -- the element lost the focus --   > 

There is no attribute that controls whether to use POST or GET with an a element.

You have to script it, if you want to abuse the semantics.

like image 25
Oded Avatar answered Oct 09 '22 01:10

Oded