You are here: Home » All Posts » HTML Forms » The HTML Form Submit Button

The HTML Form Submit Button

in HTML Forms

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: How to make a web form and get it online quickly. This article contains more information about Simfatic Forms – an easy to use form creation software.

The code below creates a form submit button:

<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.

Identifying the submit button on the server side

The name and value of the button that is pressed to submit the form is passed to the server side script. For the button above, when you click on the submit button, the data passed to the server side script is: mysubmit="Click!"

Multiple Submit buttons

You can have more than one submit buttons in a form. But, how to identify from the server side which of the buttons was pressed to submit 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(!empty($_REQUEST['Update']))
{
  //Do update here..
}
else
if(!empty($_REQUEST['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">

The server side code goes like this (PHP code):

if($_REQUEST['Operation'] == 'Update')
{
  //Do update here..
}
else
if($_REQUEST['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 using 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.

Be Sociable, Share!
  • http://supertechilltown.com Supertech Sector 2 Sohna

    Greetings! Quick question that’s entirely off topic.
    Do you know how to make your site mokbile friendly?
    My webb site looks weird when viewing from myy apple iphone.
    I’m trying to find a theme or plugin that might be able too
    fix this problem. If you have any recommendations, pleasae share.
    Thank you!

  • Web Mantra
  • Web Mantra
  • http://gm2day.com/games/ Flash Games – العاب فلاش

    good tut i like it

    :)
    good luck

  • Null

    Can you do this using javascript?

  • http://www.techblogs.in prakash

    thanks for answers, but i have to change the confirm_box text as yes and no in place of ok and cancel..

  • http://www.e-oferta.ro/ Mihai Vinatoru

    I used your solution on my website. Thank you.

    • Ankit

      Hi,

      I want to create a form with HTML.. and put the 4 button on that form.. once we click on button. All appliciation should be open on by one..
      If you have any idea please let me know.
      Form>

      </Form
      I am able to open and one form ane one button with this coding but i do not know, how to create multiple botton o n one form..

      Please be adviosed.

  • afzal

    Nice info….

  • Behzad

    Thank you.

  • http://www.azconcretecountertops.com Arizona Concrete Countertops

    Thank you! we’ve been working on creating a ‘member’ page and needed a form for log-in purposes. this answered several questions about submitting the form.

  • http://www.desmill.com Layton Miller

    A note on the purpose of efficiency–
    In the multi-form-submit example above, you don’t need to perform an ‘empty’ check.
    You can just check the existence of the variable and you’re good, which takes us from 9+ lines of code down to a mere 4 (assuming you have one line to execute):
    :)
    ============================
    if($_REQUEST[‘Update’])
    echo “Update!”;
    else if($_REQUEST[‘Insert’])
    echo “Insert!”;

    =======================
    Hope that help somebody.

    • prasanth

      if($_REQUEST['Update'])
      will fail when $_REQUEST['Update'] is set to 0. The check for existence of a variable is isset($_REQUEST['Update']) The check to make sure that a variable exists (can be 0) and is not empty is !empty($_REQUEST[‘Update’]). There no inefficiency.

  • http://postyourclassified taslim

    this site very use full for my web development diploma course

  • thusitha

    this site very use full for my web development diploma course

  • nirmala

    good

  • http://writeone.net Jonn Mero

    Hi!
    Great, but where do you put in the recipient’s address?
    Jonn

    • http://www.ovas-connect.nl/ledenadministratie Ledenadministratie

      John,
      You can put that into the form:
      Good luck

Previous post:

Next post: