I have a form on a website (www.mywebsite.com
). I have a PHP script that sends me an e-mail with information when somebody submits a form on my website. But with action="submitform.php"
in the form, it updates the site to the URL www.mywebsite.com/submitform.php
. I would like it to stay on the main site (index).
The solution for this: I added header("Location: http://mywebsite.com"); die();
to my PHP code. In this way, users will be redirected to the main site when they have submitted code.
However, this pose a new problem.
Whenever someone submit the form, I would like to display a message such as "Mail has been sent". To make this work, I tried to have a small JavaScript code, basically
document.getElementById("message").innerHTML = "Mail has been sent."
... and <div id="message"></div>
to my HTML code. Which works...... However, due to my PHP script redirecting me to my website (with header
) when someone is submitting the form, the message will only be displayed for like half a second or something.
Anyone know any workarounds for this? Thanks in advance. I can provide more detail if needed, but my problem should be clear from this. Hope anybody is able to spot my mistake...