php – html form: redirect page after form completes submit function and posts data
Question
My form looks like the following, it’s inside functions.php
<form style="text-align: center;" action="https://website/checkout/" method="POST" onsubmit="return redirect_checkout()">
<div style="position:relative; right: 107px">Where should we send it to? (postcode)<span style="color: red"> *</span></div>
<input type="text" class="form-text" size="70" name="where" id="where" />
<input type="submit" class="elementor-button elementor-size-sm" id="searchsubmit" name="searchsubmit" value="PROCEED TO CHECKOUT" />
</div>
</form>
<script type="text/javascript">
function redirect_checkout(){
<?php
$user = wp_get_current_user();
$id = $user->ID;
update_user_meta( $id, "shipping_postcode", $_POST['where'] );
?>
window.location.href = "https://website.com/checkout";
return true;
}
</script>
The problem is that the function redirect_checkout doesn’t seem to run if I call action->redirect in the form fields, and the form doesn’t redirect if I rely on window.location.href in the function. How can I get the form to redirect only after it runs the php code inside redirect_checkout()?
0
11 months
2022-03-17T19:04:17-05:00
2022-03-17T19:04:17-05:00 0 Answers
0 views
0
Leave an answer