Question

I'm building a small application in Sinatra and need to include a simple button to make a get request which will redirect the user to another page. I've been using forms for this sort of thing, which seems like overkill. Here's an example:

<form method="get" action="/users/:user_id"> // User id taken on the backend from the session.
  <input type="submit" value="User Profile">
</form>

That's a lot of markup for a simple get request. I can't seem to find any alternatives however. Is there a way to work a get such as this into a button or anchor tag?

Was it helpful?

Solution

Instead of using form and button, just do this:

<a href="/users/:user_id" class="btn">User Profile</a>

and style it CSS so that it looks like a button, for example:

a.btn {
  display: block;
  padding: 10px;
  background-color: red;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top