Question:
Can't get my website's php contact page form to do what I want and am just wondering if it's possible?
ade
2009-10-20 16:30:32 UTC
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
Four answers:
2009-10-20 18:23:43 UTC
Your current hosting package MUST allow SMTP ( http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol ) to work. Otherwise, no email can be sent.



Use any of the below sites to make the workable form you need:



For making forms:



These are really good online form makers. Just follow the instructions for making it and uploading file(s).



http://www.phpform.org/ (Best-est)

http://www.tele-pro.co.uk/scripts/contact_form/

http://jotform.com/ (WYSIWYG Form Maker)

http://www.thesitewizard.com/wizards/feedbackform.shtml

http://www.thepcmanwebsite.com/form_mail.shtml



http://emailmeform.com/

http://www.freecontactform.com/
2009-10-20 23:45:19 UTC
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:









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.
John W
2009-10-21 09:36:18 UTC
How about using a modal window for the form so everything happens from within the page the user is on. Then, you can process the form using your normal methods. E.g. http://flowplayer.org/tools/demos/overlay/modal-dialog.html
Austin @ Higher Power Media
2009-10-20 23:45:28 UTC
Here is the code i use...



This goes on the contactus.php page. (if you change the name of this page, make sure you tell the code that you changed the name




if ($_POST["emailaddress"]<>'') {

$ToEmail = 'email@address-goes.here ';

$EmailSubject = 'Contact Form ';

$mailheader = "From: ".$_POST["emailaddress"]."\r\n";

$mailheader .= "Reply-To: ".$_POST["emailaddress"]."\r\n";

$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";

$MESSAGE_BODY = "Name: ".$_POST["fullname"]."

";

$MESSAGE_BODY .= "Email: ".$_POST["emailaddress"]."

";

$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."
";

mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");

?>

Your message was sent. Someone will contact you shortly.


} else {

?>





























};

?>


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...