user2234992
user2234992

Reputation: 575

button click validation ajax

I am using a button to submit a form with ajax..all works fine..But I need to check if the button is clicked in server side page..How to do it??Any help appreciated..Thanks..

<form>

some values
</form>
<input type="button" name="delete" id="delete" value="Delete"/><br/>
<input type="button" name="edit" id="edit" value="Edit"/><br/>

Script

$("#edit").click(function(event) {
    event.preventDefault();
     $("#form1").submit()
});

$("#form1").validate({
         debug: false,
   rules: {

    plid:"required",
       },
   messages: {

    plid: "Please select a pack name id..",
    },

    submitHandler: function(form) {

    $.ajax
   ({

type: "POST",
url: "aanew.php",
data: $('#form1').serialize(),
cache: false,

success: function(response) {
    $('#result1').html(response); 

        }
        });
        }

  });

I want to carry any attribute to check if my button is set... Thanks again..

The form value passes successfully, but I need to check the button status in another page..

Upvotes: 0

Views: 1193

Answers (3)

Paul Seleznev
Paul Seleznev

Reputation: 682

You can insert into the form tag two submit buttons with different values. And on server side check - which one has come. This approach is also make adding Ajax functionality easier - because you can now add the same callback on this two buttons/

Upvotes: 0

konnection
konnection

Reputation: 433

Put this field on the form, and the other inputs too like others have already pointed

<input type="hidden" name="check_click" value="1">

then in server side

if ((isset($_POST['check_click'])) && ($_POST['check_click'] == 1))
{
//The form was clicked
}

UPDATE:

if you want for each button

    if ((isset($_POST['check_click'])) && ($_POST['check_click'] == 1))
    {
    //The form was clicked

if (isset($_POST['delete']))
{
//delete has some value
}

if (isset($_POST['edit']))
{
//edit has some value
}

    }

Upvotes: 0

chandresh_cool
chandresh_cool

Reputation: 11830

First of all your buttons in page should be in form tag like this

<form>

some values
<input type="button" name="delete" id="delete" value="Delete"/><br/>
<input type="button" name="edit" id="edit" value="Edit"/><br/>
</form>

then Simply just use isset function

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

or

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

whatever you click

Upvotes: 1

Related Questions