Form 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.
thankyou. 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.
I 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.
Yeah, the $.post is an AJAX call to send the form data to the browser. Where the response_text.html(data) is, this is your callback function which executes when you get a response from the page contact-process.php. You would need to add something in this function to check the response and if it is valid then load a new page
any 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
I've removed your other post as it's getting a bit confusing running two asking the same question.
It's difficult to give you the exact code that works as I don't know what the variable data is set to if the form submission was successful. However it will be something like the following. Replace your post with this, and work out what data equals when the form is submitted successfully
well, 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.
Ah yes, well think about what the form is doing. You're just guessing and that is going to get you nowhere because you won't learn anything. If successful, data *should* equal 'Thank You - your email has been sent.' You can change that to echo something shorter like 'Success' as it's easier to get a match against this.
So you'd have
if(empty($errors)) { if(mail('X@x.com', "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.'; } }
sadly, 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
I suggest you drop the AJAX form submissions and all JavaScript from the page and just post the form off to the contact-process.php page. When you can get that working, then add in some JavaScript validation. If you're redirecting after posting an AJAX form then you may as well not bother with the AJAX!
hmm, 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 :)
here is the code:
here is what I tried:
Any advice for how to get this working would be oh so great.
check out the form at http://getgraphixed.com/RSD_new/contact
Read more on php.net
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.
You are using Ajax to send message? Then PHP redirect won't work, you have to redirect client side using Javascript.
It's difficult to give you the exact code that works as I don't know what the variable data is set to if the form submission was successful. However it will be something like the following. Replace your post with this, and work out what data equals when the form is submitted successfully
sigh. thanks for trying to help.
So you'd have
and
and
Do I need some sort of on the actual contact form page perhaps?