In my form, there is 2 submit button (save & exit, next) & remotely checking email address duplication. it's working fine. when submitting a form I'm not getting which submit button is clicked.
form.php
<form method="post" action="" id="user_reg_form" name="user_reg_form">
<input class="form-control" id="user_id" value="<?php echo ($user->user_id!='')? $user->user_id:'0'; ?>" type="hidden" name="user_id">
<div class="no-padding">
<div class="col-md-12">
<div class="form-group no-margin">
<label>Email:</label>
<input type="text" class="form-control" name="email" id="email" value="<?php echo ($user->email!='')? $user->email:''; ?>" maxlength="50">
</div>
</div>
<div class="col-md-6">
<div class="form-group no-margin">
<label> Name</label>
<input type="text" class="form-control" name="name" id="name" value="<?php echo ($user->name!='')? $user->name:''; ?>" maxlength="50">
</div>
</div>
<div class="footer-btn" style="text-align:left;">
<input type="submit" name="save_exit" id="save_exit" class="btn btn-primary" value="Save & Exit"/>
<input type="submit" name="next" id="next" class="btn btn-success" value="Next"/>
<a href="<?=base_url('home/user')?>" class="btn btn-default">Cancel</a>
</div>
</form>
jquery validation code:
$("#reg_form").validate({
rules: {
email:{
required:true,
remote:
{
url: "<?php echo base_url('home/check_email_duplication')?>",
type: "post",
data: { 'user_id': function() { return $("#user_id").val()},'email': function() { return $("#email").val()}},
},
},
name: "required",
},
});
After form submit print $_POST array:
User Controller Action:
public function user_reg()
{
print_r($_POST);
}
Button 1 Click:
Array (
[user_id] => 14
[email] => test@test.com
[name] => yyyy
)
Button 2 Click:
Array (
[user_id] => 14
[email] => test@test.com
[name] => yyyy
)
But I Need below-expected Response in the $_POST array: Need submit button value to find out which submit button.
Button 1 Click:
Array (
[user_id] => 14
[email] => test@test.com
[name] => yyyy
[next] => Next
)
Button 2 Click:
Array (
[user_id] => 14
[email] => test@test.com
[name] => yyyy
[save_exit] => Save & Exit
)