I have two submit buttons on one form. I am using serialize method (so it will not refresh the page) to send the form data to php page. If the two buttons send data to one php page, how can I tell which part of the php script to be processed depending on the button that was pressed? Similar questions I saw on this site did not help me. My code is shown below.
HTML
<form id='form_id' action='my_page.php' method='post'>
<input type='text' name='quest1' value='$question'>
<input type='text' name='test1_id' value='$test_idq'>
<input type='text' name='test_code1' value='$code'>
<input type='text' name='class_name1' value='$class_name' >
<input type='text' name='test_name1' value='$test_nameq'>
<button id='response' class='btn btn-danger'>Response</button>
<button id='subm' class='btn btn-success''><b>Save</b></button>
</form>
Javascript
//This script processes the button with the id=subm
$('body').on('click', '#subm', function(){
$.post($("#form_id").attr("action"), $("#form_id").serialize(), function(info){ $("#msg").html(info); } );
$("html, body").animate({ scrollTop: 0 }, "slow");
});
$('body').on('submit', '#form_id', function(event){
return false;
$('#subm').click(function(){
})
});
//This script processes the button with the id=response
$('body').on('click', '#response', function(){
$.post($("#form_id").attr("action"), $("#form_id").serialize(), function(info){ $("#msg").html(info); } );
$("html, body").animate({ scrollTop: 0 }, "slow");
});
$('body').on('submit', '#form_id', function(event){
return false;
$('#response').click(function(){
})
});
PHP
<?php
include("includes/db.php");
$questn1 = $_POST['quest1'];
$class1 = $_POST['class_name1'];
$test_id1 = $_POST['test1_id'];
$t_code1 = $_POST['test_code1'];
$t_name1 = $_POST['test_name1'];
//php code continues
}
?>