I am struggling to clear all the user inputs in the blank within the form after the submit executed.
To do that, I am trying to put a function named submit()
onto a PHP file named send.php
, but I do not know whether my function code can be used in the PHP file.
Now I could create the system which send a form to my email account on a new tab on a browser. After closing the tab (thankyou.php), I can still see the user inputs in the blank on the contact page.
What I want to do is that after the user sent the form, they can be back to the contact page without any inputs in the blanks on the contact page.
The flow of the process is contact.php -> send.php -> open the new tab -> Open thankyou.php -> close the thankyou.php -> Clear the inputs in the blanks on contact.php
header('location: thankyou.php');
echo '<script type="text/javascript" language="Javascript">history.go(-1);</script>';
$_POST = submit();
function submit($name, $company, $phone, $email, $message) {
$inputs = document.getElementsByTagName('input');
for(var i = 0; i < inputs.length; i++) {
if(!inputs[i].getAttribute('type') == null){
inputs[i] = "";
}
}
return submit($name, $company, $phone, $email, $message);
}