Reputation: 1
I have this form, but when i click submit it takes me to contactform/contact.php
.
I still need the action="contactform/contact.php"
as it contains the information.
I need to redirect it to go to another link example google.com
once they click submit. I know there is a way but i cant remember it and it goes on the line of the submit which i believe was in JavaScript.
<form id="ajax-contact-form" method="post" action="contactform/contact.php">
<div class="form-option" id="main-font">Name:</div>
<div><input class="required inpt" type="text" name="name" value="" /></div>
<div style="clear:both"></div>
<div class="form-option" id="main-font">Email:</div>
<div><input class="required inpt" type="text" name="email" value="" /></div>
<div style="clear:both"></div>
<div class="form-option" id="main-font">Phone:</div>
<div><input class="required inpt" type="text" name="phone" value="" /></div>
<div style="clear:both"></div>
<div class="button-container">
<label id="load"></label><input name="submit" type="image" class="submit-btn" value="Submit" />
</div>
</form>
In the contact.php is the code for the required fields if they are missing or not. If the fields are filled and click submit it takes you to contact.php and it gives you an "OK"
I need to change the "ok" in this take me to example.com
if($mail)
{
echo 'OK';
if($autorespond =="yes")
{
include_once("autoresponde.php");
}
}
}
else
{
echo '<div class="error">'.$error.'</div>';
}
}
Upvotes: 0
Views: 1174
Reputation: 16557
Maybe this code should help. This jQuery code will listen to your submit request and would wait for 2 seconds before redirecting user.
$('#form').submit(function(e) {
e.preventDefault(); // Remove this line if you want to submit the form data as well.
var i = 0;
var x = setInterval(function() {
i++; // Just making sure that browser get enough time to submit data to server.
},1000);
if(i==2) {
window.location = "http://www.google.com"
clearInterval(x);
}
});
Upvotes: 0
Reputation: 360602
JS wouldn't help much. By the time it could trigger, the user's already leaving the page to hit your form handler script, meaning that the form page itself and any code on it is being shut down.
You should just redirect in your form handler
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
... handle form...
}
if ($form_processed_successfully) {
header("Location: http://google.com");
}
Upvotes: 1