Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to HTTP POST from a link without JS

Any methods to submit a POST request from a link if JS is disabled?

Ideeas so far (none of them perfect)

  1. Use <input type='submit>, but I need a link not a button
  2. Use <a href='' onclick='form.submit()' > but that relies on JS
  3. Use <input type='image'> ... again .. not really a link

I need a fallback method for browsers without JS, and my area for these "buttons" is too small for buttons or images

like image 696
Radu094 Avatar asked Nov 17 '09 10:11

Radu094


People also ask

How do you post a URL in HTML?

To post HTML form data to the server in URL-encoded format, you need to make an HTTP POST request to the server and provide the HTML form data in the body of the POST message. You also need to specify the data type using the Content-Type: application/x-www-form-urlencoded request header.

Can a link make a post request?

You can't. A link is a GET, by definition. It is possible to style a form submit button to look like a link, though.

Can a website run without JavaScript?

If a site is “client-side rendered” ( CSR ), that means JavaScript is doing the data fetching and creating the DOM and all that. If we're talking about websites “working” or not with or without JavaScript, a site that is client-side rendered will 100% fail without JavaScript.


1 Answers

You could make the button look like a normal link if you want using CSS?

Something like this perhaps?

<style type="text/css" media="screen">
input {
  border: none;
  background: none;
  color: #00f;
  text-decoration: underline;
  cursor: pointer;
  display: inline;
  margin: 0;
  padding: 0;
}
</style>

Click <input type="submit" value="here"/>!

Edit to add: The following CSS is just an example of how it might work, though not thorougly tested and to make it look like one of your normal links you might need to tweak it a bit.

like image 152
Huppie Avatar answered Oct 12 '22 00:10

Huppie