How can I put an Html
tag inside a PHP function, which would redirect me to another .php file?

I have been searching for hours on the web and I just can’t seem to find an answer.

What I want to do is put a <form> tag inside a php function which would redirect me to another x.php file if a certain criteria is met.

Answer

Sounds simple enough:

function myFunction() {
    if ( Some Condition Here ) {
        ?>
             <form action="x.php">
                 <button>submit</button>
             </form>
        <?php
    }
}

Obviously the “redirect” won’t happen until the form is submitted. Redirecting is done in response to an HTTP request not to “having a form”.

Leave a Reply

Your email address will not be published. Required fields are marked *