Jack Maessen Jack Maessen - 2 months ago 4
Ajax Question

how to distinguish 2 submits from each other in php with $_POST

I am having a form in which 2 inputs like below:

<input class="view" type="submit" name="viewonly" value="View">
<input class="submit" type="submit" name="vote" value="Vote">

I want to achieve this:

if(hit on input with name 'viewonly') {
echo 'you choose viewonly';
elseif(hit on input with name 'vote') {
echo 'you choose vote';

How can i do that?

My form:

<form method="post" id="quickpoll">
<input class="view" type="submit" name="quickpollsubmit" value="View">
<input class="quickpollsubmit" type="submit" name="quickpollsubmit" value="Vote">

The ajax call:

$(document).on('submit', '#quickpoll', function()
var data = $(this).serialize();

type : 'POST',
url : 'quickpoll_vote.php',
data : data,
success : function(data)



return false;



if($_POST['quickpollsubmit'] == 'Vote') {
echo 'you did vote and not view only';

The echo does not appear, so the problem is i think in the AJAX call?


Maybe you can little change you code like this:

<input class="view myclass" type="button" name="viewonly" value="View">
<input class="submit myclass" type="button" name="vote" value="Vote">
<script language="javascript">
     $('.myclass').click(function() {
         clickbuttonname = $(this).attr('name');
         var data = $(this).serialize()+'&clickbuttonname='+clickbuttonname;