Search code examples
javascriptphpjqueryhtmlforms

How to avoid redirect with simple html form submit?


I have a very simple html form I have created for a contact page. I would like to know if it is possible to disable/avoid the page redirect that occurs when the form is sent but still allow for the form to be submitted (obviously). I essentially have almost zero knowledge of php at this time and I did not create the php aspect (see form action). Any help here is greatly appreciated.

<form action="" method="post" class="flex flex--column">
                        <input type="hidden" name="toEmail" value=""/>
                        <input type="text" name="name" placeholder="Name*" required><br>
                        <input type="email" name="email" placeholder="Email*" required><br>
                        <input type="text" name="phone" placeholder="Phone"><br>
                        <input type="text" name="message" placeholder="Message*" required><br>
                        <input type="submit" value="Submit" class="submit">
                    </form>


Solution

  • Configure the form to post to a hidden iframe, as explained here: How do you post to an iframe?. The redirect will still happen, but it will be within the iframe and thus invisible to the user. It's a bit of a hack, and not the best way to do things, but it does work.