2

I have 2 submit buttons in my jQuery mobile form, and I want to evoke different actions in my target php file. I did;

<form action="target.php" method="get">
    <div data-demo-html="true">
        <input type="search" placeholder="Enter keyword" name="search" id="search" value="">
    </div>
    <div data-demo-html="true">
        <fieldset data-role="controlgroup">
            <button class="ui-shadow ui-btn ui-corner-all" type="submit" name="suba">Action1</button>
            <button class="ui-shadow ui-btn ui-corner-all" type="submit" name="subb">Action2</button>
        </fieldset>
    </div>
</form>

How can I distinguish between these two submit button clicks in my target php file?

halfer
  • 19,824
  • 17
  • 99
  • 186
Alfred
  • 21,058
  • 61
  • 167
  • 249

4 Answers4

1

give id's to button as action1 and action2, and id for foam as form.

$('#action1').click(function(){
    $('#form').prop('action', 'page1.php');
});

$('#action1').click(function(){
    $('#form').prop('action', 'page2.php');
});

this should help you.

Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41
1

You can do something like that :

if(isset($_GET["suba"])){
// First Button Clicked
else if(isset($_GET["subb"])){
// Second Button Clicked
}
Dominik
  • 101
  • 5
0

you can check as below

if(isset($_GET['suba'])){
  //button named suba is clicked
  echo "suba is cicked";
}else if(isset($_GET['subb'])){
  //button named subb is clicked
  echo "subb is cicked";
}
alamnaryab
  • 1,480
  • 3
  • 19
  • 31
0

using isset() function you can check which button is pressed.

if(isset($_GET['suba']))
    echo "suba submit button pressed";

if(isset($_GET['subb']))
    echo "subb submit button pressed";
Shailesh Katarmal
  • 2,757
  • 1
  • 12
  • 15