The HTML Form Submit Button
The basics of an HTML form submit button is discussed first in this article,
moving towards more advanced topics like multiple submit buttons.
Note:
If you are looking for a software tool for creating HTML forms quickly ( without even knowing HTML),
see the article: Form Design Software.
This article contains more information about
Simfatic Forms -
an easy to use form creation software.
In order to create an HTML form submit button, you can use the HTML code below:
<INPUT type="submit" name="mysubmit" value="Click!">
name: specifies the identification assigned to this submit button.
value: is the label that appears on the button.
The code above will create the submit button as shown below:
Identifying the submit button in the server side
The name and value of the button that is used to
submit the form is passed along with the other data to the server script.
For the button above, when you click on the submit button, the data passed to the
server side script is mysubmit=Click!
Having Multiple Submit buttons
You can have more than one submit button in a form.
But, how to identify from the server side which button submitted the form?
One way is to have different names for the submit buttons.
<INPUT type="submit" name="Insert" value="Insert">
<INPUT type="submit" name="Update" value="Update">
In the server side script you can do a check like this:
if(isset($Update))
{
//Do update here..
}
else
if(isset($Insert))
{
//Do insert Here
}
Note: The code depends on the server side scripting language you use.
The code above is in PHP.
The second method is to have different values for submit buttons with
the same name.
<INPUT type="submit" name="Operation" value="Insert">
<INPUT type="submit" name="Operation" value="Update">
and in the server side it could be handled like this:
if($Operation == "Update")
{
//Do update here..
}
else
if($Operation == "Insert")
{
//Do insert here
}
Switching the 'action' field dynamically
It is commonly required to switch the action field of the
dynamically based on certain conditions.
Read: Switching HTML form 'action' field dynamically
How to submit a form on click of a hyperlink or an image?
Read: Tutorial on JavaScript Form Submit Methods
You can find more on HTML Forms in the HTML Form Tutorial
Using Simfatic forms,
it is simple, quick & easy to create HTML forms.
Click here for more info.
|