Home › Forums › JavaScript › redirect to thankyou page with self posting php email form. Pretty please :)
- This topic is empty.
-
AuthorPosts
-
June 25, 2011 at 7:41 am #33278
rubistarr
MemberForm post to self. I like the error messages posting to the same page as the form but would love to redirect to a separate thankyou page when successfully submitted. Any help would be so wonderful.
here is the code:
if(isset($_POST) && empty($_POST))
{
require 'email-validator.php';
$validator = new EmailAddressValidator();
$errors = array();
$input_email = strip_tags($_POST);
$input_subject = strip_tags($_POST);
$input_message = strip_tags($_POST);
$required = array('Name field' => 'name', 'Email field' => 'email', 'Message field' => 'message');
foreach($required as $key=>$value)
{
if(isset($_POST[$value]) && $_POST[$value] !== '')
{
continue;
}
else {
$errors[] = $key . ' cannot be left blank';
}
}
if (!$validator->check_email_address($input_email)) {
$errors[] = 'Enter a valid email address.';
}
if(empty($errors))
{
if(mail('[email protected]', "Message from $input_name - $input_subject", $input_message, "From: $input_email"))
{
echo 'Thank You - your email has been sent.';
}
else
{
echo 'There was an issue when sending your email. Please try again.';
}
}
else
{
echo implode('
', $errors);
}
}
else
{
die('You cannot access this page directly.');
}here is what I tried:
if(empty($errors))
{
if(mail('[email protected]', "Message from $input_name - $input_subject", $input_message, "From: $input_email"))
header("Location: http://url....../thankyou-2"); /* Redirect browser */
else
{
echo 'There was an issue when sending your email. Please try again.';
}
}
else
{
echo implode('
', $errors);
}
}Any advice for how to get this working would be oh so great.
check out the form at http://getgraphixed.com/RSD_new/contact
June 25, 2011 at 8:14 am #82374June 25, 2011 at 2:13 pm #82382rubistarr
Memberthankyou. I put the exit(); into place but alas it did not solve the dilema. Basically, when I hit send the form sends perfectly but as is I am getting a blank spot above the form where the “thankyou message sent” should be instead of redirecting to a new page. You can see what I mean if you go to the contact page link above and send a message.
If I have to, I could settle for having the thankyou message post to the same page but need the form to clear at least. This is not ideal but could do if I cant solve the above.
Any help is greatly appreciated.
June 25, 2011 at 8:21 pm #82385ddliu
MemberSorry I can’t open the webpage before.
You are using Ajax to send message? Then PHP redirect won’t work, you have to redirect client side using Javascript.
June 26, 2011 at 5:58 pm #82414rubistarr
MemberI am new to the world of php java and Ajaxing so if you could give me a hint as to how to use the java script to redirect that would be great. To be honest, I am just starting to figure out php and am not really sure if I am using ajax or not. There are three files in a scripts folder that work the contact form. One is a js form with the below code and the other two are php files and then there is the main contact php page that actually shows the form.
$(function(){
$('#form_submit').click(function(){
var input_name = $('#form_name').val(),
input_email = $('#form_email').val(),
input_subject = $('#form_subject').val(),
input_message = $('#form_message').val(),
response_text = $('#response');
response_text.hide();
response_text.html('Loading...').show();
$.post('http://theme/scripts/contact-process.php', {name: input_name, email: input_email, subject: input_subject, message: input_message}, function(data){
response_text.html(data);
});
return false;
});
});June 26, 2011 at 6:11 pm #82418rubistarr
Memberany chance you could give me the actual code to add and where to add it exactly. Thanks so much for helping. It is really appreciated. I have put about 10 hrs of time into this and have learned so much about php and forms but I still have so much to learn :P
June 27, 2011 at 2:24 am #82435rubistarr
Memberstill need some advice on this one. please.
June 27, 2011 at 4:14 am #82416rubistarr
Memberwhere would I find what data equals when the form is submitted successfully. Wouldnt it be in the code I posted earlier?
June 27, 2011 at 4:53 am #82413rubistarr
Memberwell, i think I may be about to admit that I have been defeated. I have been trying to figure this out for about 2 days now and just cant seem to get it working. here is my new code with a random guess of what to put in the data spot.
$(function(){
$('#form_submit').click(function(){
var input_name = $('#form_name').val(),
input_email = $('#form_email').val(),
input_subject = $('#form_subject').val(),
input_message = $('#form_message').val(),
response_text = $('#response');
response_text.hide();
response_text.html('Loading...').show();
$.post('http://getgraphixed.com/RSD_new/wp-content/themes/fullscreen_child/scripts/contact-process.php', {name: input_name, email: input_email, subject: input_subject, message: input_message}, function(data){
if ( data === '#form_submit' )
{
window.location = "http://www.google.com/"
}
else
{
response_text.html(data);
}
});
return false;
});
});sigh. thanks for trying to help.
June 27, 2011 at 2:52 pm #82461rubistarr
Membersadly, that just makes the form say the word success above the form when it is successfully sent. Do you think it is something where the code above is overriding the code below? so the form will not redirect to the separate page? I agree guessing is not the best approach but I combine it with lots of internet research and then try things in the hopes it will work. It has gotten me this far but It appears I may have met my match :P
$.post('http://getgraphixed.com/RSD_new/wp-content/themes/fullscreen_child/scripts/contact-process.php', {name: input_name, email: input_email, subject: input_subject, message: input_message}, function(data){
if ( data === 'success' )
{
window.location = "http://www.google.com/"
}
elseand
if(empty($errors))
{
if(mail('[email protected]', "Message from $input_name - $input_subject", $input_message, "From: $input_email"))
{
echo 'success';
}
else
{
echo 'There was an issue when sending your email. Please try again.';
}Do I need some sort of
on the actual contact form page perhaps? June 27, 2011 at 2:54 pm #82462rubistarr
Memberhidden field is the missing word above
June 27, 2011 at 9:21 pm #82476rubistarr
Memberstill not solved. anyone?
June 28, 2011 at 2:51 pm #82521rubistarr
Memberhmm, but wont that defeat the point of having the error messages be on the same page as the form? I already can get it to work with the error messages and thankyou messages being on a new page. The challenge is to get it working with the errors on the same page and the thankyou on a new page. It can be done right :)
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.