Problem Statement
Which button type submits the form?
Explanation
The button with type equals submit submits the form. When clicked, it triggers form submission, sending all form data to the URL specified in the form's action attribute. You can create submit buttons using either input type equals submit or button type equals submit. The button element is more flexible because you can include HTML content like images or icons inside it, while input only allows text. The value or inner text of the submit button appears as the button label. If a form has multiple submit buttons with different names and values, you can determine which button was clicked on the server side. Submit buttons are essential for allowing users to send their form data.
Code Solution
SolutionRead Only
<!-- Submit button using input -->
<form action="/submit" method="POST">
<input type="text" name="username" placeholder="Username">
<input type="submit" value="Submit">
</form>
<!-- Submit button using button element -->
<form action="/register" method="POST">
<input type="email" name="email" placeholder="Email">
<input type="password" name="password" placeholder="Password">
<button type="submit">Create Account</button>
</form>
<!-- Multiple submit buttons -->
<form action="/save" method="POST">
<textarea name="content"></textarea>
<button type="submit" name="action" value="draft">Save as Draft</button>
<button type="submit" name="action" value="publish">Publish</button>
</form>
<!-- Submit with icon -->
<form action="/search" method="GET">
<input type="text" name="q" placeholder="Search...">
<button type="submit">
🔍 Search
</button>
</form>