Can't get my website's php contact page form to do what I want and am just

  • Thread starter Thread starter happyade
  • Start date Start date
H

happyade

Guest
wondering if it's possible? I understand quite a bit about web design, but always seem to get stuck when it comes to contact forms.

What I would like is for me to have a form where the user can enter say: name, email, phone number and a message, then have a submit button.

I can do this where after pressing submit you get sent to a separate php page that sends the email and then displays something on that seperate php page like "Thankyou for you message" with an o.k link that will return you to the original page.

What I would like to have happen though, is for the user to fill out the form, press submit and then just to have something like a little tick appear next to the submit button saying message sent. In other words, have the email processing happen on the same page.

I kind of got this working by including all the php on the same contact page. My only problem is that once the user clicks submit and their message is sent and a message appears by the form saying message sent...

if the user then refreshes the page, the form is sent again and I get two emails from the same user or i get an alert box telling me the form data will be resent. Annoying! Can I stop this resending of form data on page refresh?

Any advice or help would be great. Is there a better way of doing this?

Hope I made myself clear,

thanks
 
This effect can be achieved by using jQuery, a JavaScript derivative. You will want to use jQuery's $.ajax ( ... ) function to send the form information to the PHP page to send the email. And when the response text is achieved, that is when you display the message. However, I believe you should do this a different way:
EXAMPLE CODE:
<form name='contactme'>
<input name='whatever' type='text' />
<input type='submit' value='Submit' />
</form>
When the user hits the submit button, use:
$fadeOut('contactme');
$fadeIn('Your email is being sent...');
Which will make the entire form fade-out, and prevent the user from resending the message. Then the message "Your email is being sent..." will appear. When you recieve the response text from the PHP page, you should include a function that add "SENT!" to the end of the fadein message, resulting in:
"Your email is being sent... SENT!"
I'm sure you are thinking that I am making no sense.
Visit http://www.jquery.com to learn it. It makes animations and stuff like this much easier.
Good Luck!
If you need further assistance/advice, feel free to contact me.
 
Back
Top