<input type="image"> creates an image that acts as a form submit button. When the user activates the image, the form is submitted just like a submit button, and a mouse or pointer click can also submit the click coordinates.
<input type="image" name="save" src="images/savechanges.jpg" alt="Save changes">
<button type="submit"> is easier to style, label and maintain.The original Plus2net example uses the existing images/savechanges.jpg asset as the submit control:
<form method="post">
<input type="image"
name="imgbtn"
src="images/savechanges.jpg"
alt="Save changes">
</form>
<input> is a void element, so it does not use a closing </input> tag.
action for this submit control.border attribute is obsolete. Use CSS such as border or border: 0 when visual styling is required.An image submit control can submit the horizontal and vertical coordinates where the image was clicked. With name="imgbtn", the submitted field names are based on imgbtn.x and imgbtn.y. PHP normally exposes dots in submitted field names as underscores, so these commonly appear as $_POST['imgbtn_x'] and $_POST['imgbtn_y'].
<input type="image"
name="imgbtn"
src="images/savechanges.jpg"
alt="Save changes">
The coordinates should not be treated as trusted data. If an application actually uses them, validate them on the server.
Enter your name and activate the existing image submit button:
The HTML for the form is:
<form method="post" action="html_frmimgbtn.php#form">
<label for="visitor-name">Your name</label>
<input type="text" id="visitor-name" name="t1">
<input type="image" name="imgbtn" src="images/savechanges.jpg" alt="Submit name">
</form>
Because type="image" is a submit control, it can override selected form submission settings in the same way as a submit button.
<form action="save.php" method="post">
<input type="image"
src="images/savechanges.jpg"
alt="Preview changes"
formaction="preview.php"
formtarget="_blank">
</form>
Use these overrides only when a form genuinely needs different submit actions. Every destination must independently validate submitted data. POST changes how data is sent, but it is not encryption; use HTTPS for sensitive information.
The alt text should describe the button's action, such as alt="Save changes" or alt="Search". It is not simply tooltip text.
alt="image" or alt="button".An image submit button submits a form. An image inside an anchor navigates to another URL. These are different interactions.
<!-- Image link: navigation -->
<a href="site_map.php">
<img src="images/html.jpg" alt="HTML tutorial home">
</a>
Do not add the obsolete border="0" attribute to the image. If an unwanted border is introduced by styling, control it with CSS.
alt provides a text alternative and accessible name. Write it as the action the control performs.
Use CSS for borders and other visual presentation.
<input> is a void element and does not have an end tag.
Pointer activation can also submit x/y coordinates. Applications should not build security decisions around those client-supplied values.
Use an <a href> for navigation. Use a submit control when the purpose is to submit a form.
It displays an image as a submit control. Activating the image submits its associated form.
Yes. Pointer activation can submit x and y coordinates in addition to the form's other successful controls.
Use text that describes the button's action, such as Save changes, Search or Submit order.
The old presentational border attribute is obsolete. Use CSS to control borders.
Yes. As a submit control, it can use submit-button override attributes such as formaction, formmethod, formenctype, formtarget and formnovalidate.
Use an image button to submit a form. Use an image inside an anchor when the purpose is navigation to another URL.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| Sriram Narasimhan | 30-05-2014 |
| Nice tutorials | |