php – html form: redirect page after form completes submit function and posts data


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" />
<script type="text/javascript">
function redirect_checkout(){
        $user = wp_get_current_user();
        $id = $user->ID;
        update_user_meta( $id, "shipping_postcode", $_POST['where'] );
        window.location.href = "";
        return true;

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()?

Griffin 5 months 2022-03-17T19:04:17-05:00 0 Answers 0 views 0

Leave an answer