A user logs in to his control panel and sees his incoming messages. Near each message there is a "Reply" button. What is the correct way to implement that button?
I see three main options:
Use a link:
<a href="customer.php?reply&messageid=1234">Reply</a>.
Disadvantage:
Use a button:
<button onclick="location.href='customer.php?reply&messageid=1234'">Reply</button>`
Disadvantage:
Use a form with <input type="submit">
:
<form action="customer.php?reply" method="get">
<input name="messageid" type="hidden" value="1234" />
<input type="submit" value="Reply" />
</form>
Disadvantage:
Some other notes:
Which one would you choose and why?
UPD. Well, I have decided to use a link. Thank you everyone for discussion!
input suggests that the control is editable, or can be edited by the user; button is far more explicit in terms of the purpose it serves. Easier to style in CSS; as mentioned above, FIrefox and IE have quirks in which input[type="submit"] do not display correctly in some cases.
Definition and Usage. The <input type="submit"> defines a submit button which submits all form values to a form-handler. The form-handler is typically a server page with a script for processing the input data. The form-handler is specified in the form's action attribute.
It depends on your purpose. In your code, if you want to submit the form to your server, you should use "Submit". However, if you want to do something from client side by clicking the "Button", the input type "Button" is the choice.
The <button> tag permits phrasing content inside button element contents like text or images etc, along work with type functionality defined. But the input type=”button” attribute does not permit content.
I would definitely use a link: progressive enhancement.
You want the button to be usable even with Javascript turned off (remember: every user is a non-javascript-user for the duration of the page load. If they're on a slow connection (e.g. mobile), they should be able to reply as soon as they see the button).
Styling is a non issue (you weren't gonna use the default button styles, were you?).
Using POST when the user isn't submitting anything sure is wrong. Even with GET, it's still not really form material...
It's pretty easy to style <a>
and <button>
identically, just use a common class name. <input type="button">
can be a little trickier, but you don't need to use it.
Your tag choice should never be dictated by your intended presentation, but what the element is and what it does. Links should be marked up as
<a>
.
I agree that a POST
is wrong. So, set your form to use method="get"
. Use just one form and leave out the hidden fields. Using <button>
, the displayed text can differ from the submitted value.
<form action="customer.php" method="get">
<input type="hidden" name="reply" />
<div class="message">
<div class="messageBody">..</div>
<button name="messageid" value="1234">Reply</button>
</div>
<div class="message">
<div class="messageBody">..</div>
<button name="messageid" value="1235">Reply</button>
</div>
...
</form>
All methods are correct, except that method 2 is correct only under the assumption that you can safely ignore non-JavaScript browsing.
The assumptions and comments presented about forms are incorrect, or at least misleading. A form need not involve user input; forms can be used e.g. to submit previously collected data, with no other fields but a submit field. And the POST method can be used even when not changing anything, e.g. due to the amount of input data (as there are fairly low upper limits on GET data); besides, the form presented in the question uses GET, the default method.
Otherwise, this is mostly a non-constructive question, calling for discussion and argumentation rather than technical solutions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With