DW How 2 Make Contact Form
DW How 2 Make Contact Form
DW How 2 Make Contact Form
We found a great website on the net called http://dreamweaverspot.com and we have basically followed their tutorial for creating Contact Forms. We also checked out a few other tutorials we found by Googling, but the dreamweaverspot one seemed to be the simplest one for beginners. When a Contact Form is made, there are two key parts: a PHP script and a Webpage Form. A PHP script is a set of instructions that needs to be downloaded from the following location: http://www.passyworld.com/PWorldContactUs/formtoemail.zip and then extracted. If our web host does not allow scripts to run, then later on we will find that our new contact us page does not work. If this happens we will have to forget about PHP and forms. Instead of using PHP we can easily make and put an image onto the Contact Us page like this one:
People can then create their own email to us. (So we can get by without PHP if we need to). The second part of the Contact Form is to create the Contact Us webpage with a Form on it using Dreamweaver. Lets first look at how we modify and set up the PHP script.
Page 1 of 17
The only other thing is to now save this file into our Dreamweaver site folder, and make sure the file type is set to the PHP group, and the filename (which is case sensitive) is exactly FormToEmail .
Page 2 of 17
Choose File > Save, name it ContactForm.htm then save the document into your local site folder. We now need to setup the background image for our ContactForm.htm HTML code. To do this, we do from the top of page menu: Modify > Page Properties and then click on browse next to Background image, and navigate to where our image is, and then click OK.
Page 3 of 17
We can also use our mouse to click onto the Div Box and stretch its size and shape, and move it around the page. We can thus make something like this:
Page 4 of 17
We next need to click our mouse inside this Div Box, to get a big vertical flashing cursor. Now do Insert > Form then select Form from the Flyout Menu. Now in the Properties Inspector at the bottom of the DW screen: In the Action text box type in FormToEmail.php (this is the file we set up on our site earlier). Change the Method to POST and then in the NAME text box type in ContactForm. This is all shown below on the next page: How to Create a Contact Us Page in Dreamweaver Page 5 of 17
Next step is to place the form objects onto the page (the information we would like to collect). We need text boxes for Name and Email Address, and also a Text Area for Comments. To do this click inside our form object (which is defined by a dotted red rectangle in DW:
and then from the top menu select Insert > Form > Label. From the Code Window click in between the LABEL Tags and type in Name:.
Page 6 of 17
Click the OK button. Test your Form to see how it is going, by Saving and then clicking the planet earth icon (or F12 key) to check how it is working.
Page 7 of 17
And then hold down the shift key, and press the Enter key a couple of times: We can make the white text boxes display at maximum width, by clicking on them, and in the Properties inspector at the bottom of DW, set them to have Char Width values of 80 to display them on screen as 80 characters wide. We can also click in the code view onto the label names, and then in the Properties at the bottom of DW, change Font, size, and color, like this:
Page 8 of 17
Save the page and use the Planet Earth icon of F12 to test it in the browser and confirm it is working ok.
Page 9 of 17
Note that FormToEmail.php is displayed in the bottom left hand corner of the web screen. Well in Local mode we just get a pop up window that asks us if we would like to Open or Save the FormToEmail.php file. If we click open, it just opens the PHP file in Dreamweaver and does not send an email. Hopefully it will work when we ship all the components to our web host server. However, before we do that we need to add a Rollover Link button to our page so that we can click it to go back to our sites Home page when we are done with the email submit. We can use the Home button images we already have setup for our Homepage, from back
Page 10 of 17
They are already stored on our site in the Folder PWorldImages and so we should just be able to point to them. We need to add an AP Div to place the Rollover link into, which we do by the top of page : Insert > Layout Objects > AP Div and then move it into position, and set its Width to 94 and Height to 101 in the bottom of screen Properties Inspector. Now Click inside the Div box, and on the top of screen menu do Insert > Image Objects > Rollover Image and then set the pop up box to have the two images linked to and set the link to be to Index.html like this:
Click ok and then test the webpage using F12 to see that the link works ok locally. We also need to modify our Index.HTML homepage so that it now links to this Contact Us page instead of its current link to an under construction page.
Page 11 of 17
and when we click the Submit button, it appears to run the PHP and give us a successful end message (that we know is coded into the PHP script):
Page 12 of 17
However, when we go to check our destination email inbox at [email protected] there are no emails in there. We will have to raise a help request with our Web Hosting Company and see if they can figure out why the script runs ok, but produces no resulting email to our inbox. Maybe our host will output the test emails to us in the next day or so. Anyway, we have seen how to make a form inside a webpage in Dreamweaver, and combine it with a PHP script, just like business sites do in the real world. So it has not been a total waste of time. If we cannot get the page working, we will have to go back to the simple display of an image** of our email address, for people to use their own email program to contact us. We display the email address in an image, rather than as text on our web page to prevent spiders and spammers from capturing our email address by reading our pages source code.
Page 13 of 17
How to Make a Contact Us PAGE in Dreamweaver Getting the PHP Script Working
We raised a help request with our web hosting company Namecheap.com (who may I say are always sensational at supplying support answers within 24 hours and highy recommended). The showstopper is because of Spammer problems, our host does not let the From field on an email be the sender's email address. The from field must be something that cannot be replied to, that is on our Host's server such as: [email protected] Namecheap.com also kindly supplied us the following sample PHP: -------------------------------------------------------------------<?php $mail_to_send_to = "[email protected]"; $your_feedbackmail = "[email protected]"; $sendflag = $_REQUEST['sendflag']; if ( $sendflag == "send" ) { $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $headers = "From: $your_feedbackmail" . "\r\n" . "Reply-To: $email" . "\r\n" ; $a = mail( $mail_to_send_to, "Feedback Form Results", $message, $headers ); if ($a) { print("Message was sent, you can send another one"); } else { print("Message wasn't sent, please check that you have changed emails in the bottom"); } } ?> <form method="post" action="feedback.php"> <input type="hidden" name='sendflag' value="send"> Your Email: <input name="email" type="text" /><br /> Message:<br /> <textarea name="message" rows="15" cols="40"> </textarea><br /> <input type="submit" /> </form>
--------------------------------------------------------------------
Page 14 of 17
We also need to change the variable names in the Namecheap PHP to match our form which has: Person's Name = name (we will need to add this variable to the Namecheap script) Person's email address = email (this matches our form HTML ok already) Persons comment text is 50 chars by 10 lines, not 40x15 and = "comments" (not "message") The bottom part of the PHP builds a form on the screen, which we do not need, and so we will delete it. We will replace it with some HTM code form our old PHP that says thankyou, it was sent. We also have to save this PHP with a name of "feedback.php" and set the Action field on our form in Dreamweaver to be "feedback.php" . We also needed to remove the If statement, and make a few other changes to end up with this as our final PHP: -------------------------------------------------------------------<?php $mail_to_send_to = "[email protected]"; $your_feedbackmail = "[email protected]"; { $email = $_REQUEST['email'] ; $name = $_REQUEST['name'] ; $message = $_REQUEST['comments'] ; $headers = "From: $your_feedbackmail" . "\r\n" . "Reply-To: $email" . "\r\n" . "Name: $name" . "\r\n" ; $a = mail( $mail_to_send_to, "PW Contact Us Message", $message, $headers ); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Contact Form PHP</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#ffffff" text="#000000">
Page 15 of 17
and the click here takes us back to the home page (we set this link up using Dreamweaver) How to Create a Contact Us Page in Dreamweaver Page 16 of 17
The problem with this email is that it does not give us the persons email address or their name which they entered onto our original form. This is the main drawback to using hotmail. If we use the email service provided by our web host, by sending our email to [email protected] instead of to [email protected] then we get an email with headers where we can see the senders email in the Reply-To: header like this:
So the Best advice we can give on making a Contact Us webpage, is to obtain a model PHP script from your web host, and not blindly try to make one yourself. If you are using a great web hosting company like Namecheap.com, then this should be a breeze.
Page 17 of 17