dukevin
dukevin

Reputation: 23178

1 form 2 actions

<form name="ipladder" id="ipladder" action="/checkuser/master-check.php"  method="post">
<input name="ipladder" type="text" id="ipladder" />

<input type="submit" name="submit" id="botton" value="Check" /> 
<input type="submit" name="geo" id="botton"/>
</input></form>

I have one input box and 2 submit buttons. When the first button is pressed (name="submit") I want it to go to master-check.php as specified in the action= parameter. However when the geo button is pressed, I want it to go through a different action which I haven't specified because I didn't know how to do so.

What can I do so I can have 1 input box and 2 buttons each processing through different action files?

Upvotes: 1

Views: 11829

Answers (4)

Salman Aslam
Salman Aslam

Reputation: 781

Well you can achieve your goal by single php page as well. on mastercheck.php something like this can help you.

    <?php 
    if($_POST['submit'])
    {
       //you code for master-check.php
    }
else if(isset($_POST['geo']))
{
   //you code for other page goes here
}
?>

Upvotes: 0

Mr.J4mes
Mr.J4mes

Reputation: 9266

Instead of using form action, I think you can use Ajax to achieve what you want. It will be something like this:

<form name="ipladder" id="ipladder" method="post">
    <input type="text" id="ipladder2" name="ipladder2" />
    <input type="button" id="button1" name="submit" value="Check" onclick="action1()" />
    <input type="button" id="button2" name="geo"    value="Something else" onclick="action2()" />
</form>

and in the header you can define 2 Ajax functions:

<script type="text/javascript">
    function action1() 
    {
        $.ajax({
           type: "POST",
           url: "/checkuser/master-check.php",
           data: $("ipladder2").val(),
           success: //do something,
           dataType: //return dataType
        }); 
    }

    function action2() 
    {
        $.ajax({
           type: "POST",
           url: //other URL,
           data: $("ipladder2").val(),
           success: //do something else,
           dataType: //return dataType
        }); 
    }
</script>

Upvotes: 2

m0skit0
m0skit0

Reputation: 25873

Make a single PHP script that handles which button has been pressed and then redirects to correct PHP handling script (after correcting what Juhana commented of course).

Upvotes: 2

Bas Slagter
Bas Slagter

Reputation: 9929

Maybe you can try altering the "action" parameter of your form in an onclick method that, after changing, submits the form. Something like:

$('#btn1').click(function(){
  $('#ipladder').attr('action', 'location1.php');
  $('#ipladder').submit();
});

$('#btn2').click(function(){
  $('#ipladder').attr('action', 'location2.php');
  $('#ipladder').submit();
});

Another option of couse, is to post to 1 page...and handle the logic (some redirect or whatever) there.

Upvotes: 3

Related Questions