I need to submit a form and unset the session on submit at the same time on click.
This is currently my form and button :
<form method="post" action="" id="formID">
//content here
<button class="btn btn-success" type="submit" name="submit_req" value="submit_req"
onclick="submitForm('insert_man_order.php')">Submit Request</button>
</form>
This is my PHP for unsetting the session and resetting the value of my variable :
if(isset($_POST['submit_req'])){
if(!empty($_SESSION['cart'])){
foreach($_POST['quantity'] as $key => $val){
$val == 0;
unset($_SESSION['cart'][$key]);
}
}
}
JS :
function submitForm(action)
{
document.getElementById('formID').action = action;
document.getElementById('formID').submit();
}
The form submission is working but the session and $val
are not unsetting/resetting. Any help will be appreaciated.
Thanks