Hi iam updating the form in php. I have two buttons like save and submit button. Need to display different message for save and submit button (now displaying same message for both.)
<?php include 'includes/db.php';
if(isset($_POST['submit_user']) || isset($_POST['save_users']) ){
$formsubmitstatus = isset($_POST['submit_user'])?1:0;
$firstname=$_POST['first_name'];
$father_name=$_POST['father_name'];
$user_gender=$_POST['user_gender'];
$nationality=$_POST['nationality'];
$dob=$_POST['dob'];
$place_of_practice=$_POST['place_of_practice'];
$id= $_POST['users_id'];
$ins_sql = "UPDATE users set first_name='$firstname',father_name='$father_name',user_gender='$user_gender',nationality='$nationality',dob='$dob',status='3', profile_submit_status='$formsubmitstatus',place_of_practice='$place_of_practice' WHERE users_id = $id";
$run_sql = mysqli_query($conn,$ins_sql);
$msg = 'Personal Details have been Submitted';
$msgclass = 'bg-success';
//header("Location: edit.php");
}else {
$msg = 'Record Not Updated';
$msgclass = 'bg-danger';
}
?>
<form class="form-horizontal" action="edituser.php?id=<?php echo $row['users_id'] ;?>" method="post" role="form" enctype="multipart/form-data">
<?php if(isset($msg)) {?>
<div class="<?php echo $msgclass; ?>" id="mydiv" style="padding:5px;"><?php echo $msg; ?></div>
<?php } ?>
<input type='hidden' value='<?=$id;?>' name='users_id'>
<div class="form-group">
<label for="firstname" class="col-sm-2 control-label">1. Name of the Candidate( As per Law Degree Certificate )</label>
<div class="col-sm-9">
<input type="text" class="form-control" value="<?php echo $oppointArr['first_name'];?>" name="first_name" id="first_name" >
</div>
</div>
<div class="col-sm-offset-2">
<?php if($oppointArr['profile_submit_status'] == 0){ ?>
<button type="submit" class="btn btn-default" name="save_users" id="save_users">Save</button>
<button type="submit" class="btn btn-default" name="submit_user" id="subject">Submit Application Details</button>
<?php } ?>
<!--<button type="cancel" class="btn btn-raised"><a href="http://dfstagingserver.com/enrolment/employee/edit.php">Cancel</a></button>-->
</div>
</form>
Need to display different message for save button and Submit button.
Advertisement
Answer
Just change the $msg according to ($_POST[‘submit_user’]) or ($_POST[‘save_users’])
(1) change this line
$msg = 'Personal Details have been Submitted';
to
if ($_POST['submit_user']) {
$msg = 'Personal Details have been Submitted (submit button pressed)'; }
if ($_POST['save_users']) {
$msg = 'Personal Details have been Submitted (save button pressed)'; }
(2) and please change the lines
<button type="submit" class="btn btn-default" name="save_users" id="save_users">Save</button> <button type="submit" class="btn btn-default" name="submit_user" id="subject">Submit Application Details</button>
to
<button type="submit" class="btn btn-default" name="save_users" value="save_users" id="save_users">Save</button> <button type="submit" class="btn btn-default" name="submit_user" value="submit_user" id="subject">Submit Application Details</button>
Note: codes updated and tested in a real server of real DB