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;
}
Frage
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?
Lösung
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;
}