1

Possible Duplicate:
How can I tell which button was clicked in a PHP form submit?

I have a couple of submit buttons on my page, each one is going to insert the entered values into the sql db.

What I am hoping to do is capture which submit button was hit perform the related insert Statement then reload the page displaying the new values.. However I am just not sure how to do it.

I am used to specifying my post like so

<form action="orderform.php" method="post"
onsubmit="document.getElementById('myButton').disabled=true;
document.getElementById('myButton').value='Submitting...';"
>

The action is specifying a different .php doc.. I would like to some how make it so that when a submit button is selected it just goes to a function on the current page.. Is this possible? if so could you provide an example or link to an example as I just don't know what this would be called being new to PHP.

Community
  • 1
  • 1
HurkNburkS
  • 5,492
  • 19
  • 100
  • 183

1 Answers1

1

if you are on orderform.php and you want to access function on the orderform.php just write the php on the top of the page

and you can detect the submit button by the adding the name in submit like

<input type="submit" value="Submit" name="submit_first">

and in php check

if(isset($_POST['submit_first']))

full example test.php

<?php
      if(isset($_POST['submit_first']))
      echo'this is form the submit first';
  ?>
<html>
    <head></head>
    <body>
        <form name="input" action="test.php" method="POST">
            Username: <input type="text" name="new-user">
            <input type="submit" value="Submit" name="submit_first">
        </form> 
    </body>
</html>
Database_Query
  • 626
  • 4
  • 14