January 28, 201016 yr Hey guys I am new to web design, I know a little about creating a css site but nothing about php, jquery etc, i'm now starting to get into the more difficult pages starting with what i thought was a simple process. I just want a simple contacts page, Name, email, location, and comments and an email sent to me once they have submitted their details, everything seems to work how i want it apart from the rollover image, can anyone help me out with this, i have posted the codes for the php script and my html form if that helps? Thanks dan **************************************************************************Here's my HTML code <form name="form1" action="contactformprocess.php" method="POST"> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr bgcolor="#FFFFFF"> <td width="20" height="30"> </td> <td width="113" height="30"> Name</td> <td height="30" width="234" class="text"><span> <input name="name" type="text" id="name" value="" size="20"> </span></td> </tr> <tr> <td width="20" height="30"> </td> <td width="113" height="30"> Location</td> <td height="30" width="234" class="text"><span> <input type="text" name="location" value="" size="20"> </span></td> </tr> <tr bgcolor="#FFFFFF"> <td width="20" height="30"> </td> <td width="113" height="30">Email Address</td> <td width="234" height="30" class="text"><span> <input name="email" type="text" id="email" size="20" maxlength="50"> </span></td> </tr> <tr bgcolor="#FFFFFF"> <td width="20" height="30"> </td> <td width="113" height="0">Comments</td> <td width="234" height="30" class="text"><p name="geff" cols="40" rows="6"><span name="geff" cols="40" rows="6"> <textarea name="comments" cols="40" rows="6"></textarea> </span></p></td> </tr> <tr bgcolor="#FFFFFF"> <td width="20" height="30"> </td> <td width="113" height="30"></td> <td width="234" height="30" class="text"><span> <a href="java script:document.form1.submit();" title="Submit the Form"><img src="images/About_Us_Home_Btn_1.jpg" onmouseover="this.src='images/About_Us_Home_Btn_2.jpg';" onmouseout="this.src='images/About_Us_Home_Btn_1.jpg';" height="14" width="104" border="0"></a> </span></td> </tr> </table> </form> ********************************************************************************************Here's my PHP Code <?php /* Email Variables */ $emailSubject = 'My Enquiry'; $webMaster = 'my email address'; /* Data Variables */ $name = $_POST['name']; $email = $_POST['email']; $location = $_POST['location']; $comments = $_POST['comments']; $body = <<<EOD <br><hr><br> Name: $name <br> Email: $email <br> Location: $location <br> Comments: $comments <br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Results rendered as HTML */ $theResults = <<<EOD <html> <head> <title>sent message</title> <meta http-equiv="refresh" content="3;URL=http://mywebsite.com/index.html"> <style type="text/css"> <!-- body { background-color: #444; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 20px; font-style: normal; line-height: normal; font-weight: normal; color: #fec001; text-decoration: none; padding-top: 200px; margin-left: 150px; width: 800px; } --> </style> </head> <div align="center">Thank you for your email</div> </div> </body> </html> EOD; echo "$theResults"; ?>
January 28, 201016 yr Replace: <a href="java script:document.form1.submit();" title="Submit the Form"><img src="images/About_Us_Home_Btn_1.jpg" onmouseover="this.src='images/About_Us_Home_Btn_2.jpg';" onmouseout="this.src='images/About_Us_Home_Btn_1.jpg';" height="14" width="104" border="0"></a> With: <a class="submit" href="java script:document.form1.submit();" title="Submit the Form">Submit Form</a> Then add this to your CSS: .submit, .submit:visited{ background:url('About_Us_Home_Btn_2.jpg'); text-indent:-500em; } .submit:hover, .submit:visited:hover{ background:url('About_Us_Home_Btn_1.jpg'); } It would be better to use a large image which contains both images you want to swap. Then align the background from bottom to top on hover. Just a more efficient method PS. You should do some sanitising with the posted fields before mailing.
January 28, 201016 yr Author Replace: <a href="java script:document.form1.submit();" title="Submit the Form"><img src="images/About_Us_Home_Btn_1.jpg" onmouseover="this.src='images/About_Us_Home_Btn_2.jpg';" onmouseout="this.src='images/About_Us_Home_Btn_1.jpg';" height="14" width="104" border="0"></a> With: <a class="submit" href="java script:document.form1.submit();" title="Submit the Form">Submit Form</a> Then add this to your CSS: .submit, .submit:visited{ background:url('About_Us_Home_Btn_2.jpg'); text-indent:-500em; } .submit:hover, .submit:visited:hover{ background:url('About_Us_Home_Btn_1.jpg'); } It would be better to use a large image which contains both images you want to swap. Then align the background from bottom to top on hover. Just a more efficient method PS. You should do some sanitising with the posted fields before mailing. Hi Andy Thanks for the reply. Like i said i'm new to this so i don't understand alot of what people say at the moment what does PS. You should do some sanitising with the posted fields before mailing. mean and how do i do that? also, i've just followed you instructions and the image is replaced by blue submit form text and a pop up saying Firefox can't find the file at /Users/Home/Sites/my site/java script:document.form1.submit();. where do i get this ava script:document.form1.submit(); from? Dan
January 28, 201016 yr Hi Andy Thanks for the reply. Like i said i'm new to this so i don't understand alot of what people say at the moment what does PS. You should do some sanitising with the posted fields before mailing. mean and how do i do that? also, i've just followed you instructions and the image is replaced by blue submit form text and a pop up saying Firefox can't find the file at /Users/Home/Sites/my site/java script:document.form1.submit();. where do i get this ava script:document.form1.submit(); from? Dan You should sanitise inputs before using them with emails and databases etc. It's a security precaution. Anyone could enter HTML code into the field and submit it. This could cause some serious security threats - they could embed their own script within the HTML email etc. To sanitise, I use this home-made PHP function: function clean($text) { $text=trim(strip_tags(mysql_real_escape_string($text))); //$text = htmlentities($text); // This line is for cleansing HTML emails return $text; } So, to use this, add the function above to your PHP file, and then replace this: $name = $_POST['name']; $email = $_POST['email']; $location = $_POST['location']; $comments = $_POST['comments']; With this: $name = clean($_POST['name']); $email = clean($_POST['email']); $location = clean($_POST['location']); $comments = clean($_POST['comments']); I assumed you had some javascript which would handle the form when you click that link. You need to catch the submit link using javascript, or just use the usual; <input type="submit" value="Submit Form" id="submitForm" /> Make sure in your CSS that the link to the images is relative to the CSS file, not the contact form file. EDIT: Replace this: <a class="submit" href="java script:document.form1.submit();" title="Submit the Form">Submit Form</a> With this: <input type="submit" value="Submit Form" class="submit" /> And replace your CSS: .submit, .submit:visited{ background:url('About_Us_Home_Btn_2.jpg'); text-indent:-500em; } .submit:hover, .submit:visited:hover{ background:url('About_Us_Home_Btn_1.jpg'); } With this: .submit{ background-image:url('link_to_normal_image'); text-indent:-500em; width:140px; /* Adjust as necessary (image size) */ height:30px; /* Adjust as necessary (image size) */ border:0; } .submit:hover{ background-image:url('link_to_hover_image'); } This works for me in Chrome, Firefox and Safari. Edited January 28, 201016 yr by andyl
January 28, 201016 yr Author You should sanitise inputs before using them with emails and databases etc. It's a security precaution. Anyone could enter HTML code into the field and submit it. This could cause some serious security threats - they could embed their own script within the HTML email etc. To sanitise, I use this home-made PHP function: function clean($text) { $text=trim(strip_tags(mysql_real_escape_string($text))); //$text = htmlentities($text); // This line is for cleansing HTML emails return $text; } So, to use this, add the function above to your PHP file, and then replace this: $name = $_POST['name']; $email = $_POST['email']; $location = $_POST['location']; $comments = $_POST['comments']; With this: $name = clean($_POST['name']); $email = clean($_POST['email']); $location = clean($_POST['location']); $comments = clean($_POST['comments']); I assumed you had some javascript which would handle the form when you click that link. You need to catch the submit link using javascript, or just use the usual; <input type="submit" value="Submit Form" id="submitForm" /> Make sure in your CSS that the link to the images is relative to the CSS file, not the contact form file. Andy Your being really helpful but i just can't get my head round it. Is their any chance you can adjust my code that i posted so i can just copy and paste it, then i can compare both sets of php files and html files and hopefully learn how to do this once and for all, it would be a big help, otherwise i feel i could be on this all night asking the same dum questions Dan
January 28, 201016 yr I apologise if I'm not making sense Put this in your <head> tag on the page which you want the form displayed: <style type="text/css"> .submit{ background-image:url('link_to_normal_image'); text-indent:-500em; width:140px; /* Adjust as necessary (image size) */ height:30px; /* Adjust as necessary (image size) */ border:0; } .submit:hover{ background-image:url('link_to_hover_image'); } </style> Then replace all first posted code (contact form code) with this: <form name="form1" action="contactformprocess.php" method="POST"> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr bgcolor="#FFFFFF"> <td width="20" height="30"> </td> <td width="113" height="30"> Name</td> <td height="30" width="234" class="text"><span> <input name="name" type="text" id="name" value="" size="20"> </span></td> </tr> <tr> <td width="20" height="30"> </td> <td width="113" height="30"> Location</td> <td height="30" width="234" class="text"><span> <input type="text" name="location" value="" size="20"> </span></td> </tr> <tr bgcolor="#FFFFFF"> <td width="20" height="30"> </td> <td width="113" height="30">Email Address</td> <td width="234" height="30" class="text"><span> <input name="email" type="text" id="email" size="20" maxlength="50"> </span></td> </tr> <tr bgcolor="#FFFFFF"> <td width="20" height="30"> </td> <td width="113" height="0">Comments</td> <td width="234" height="30" class="text"><p name="geff" cols="40" rows="6"><span name="geff" cols="40" rows="6"> <textarea name="comments" cols="40" rows="6"></textarea> </span></p></td> </tr> <tr bgcolor="#FFFFFF"> <td width="20" height="30"> </td> <td width="113" height="30"></td> <td width="234" height="30" class="text"><span> <input type="submit" value="Submit Form" class="submit" /> </span></td> </tr> </table> </form>
January 28, 201016 yr Author I apologise if I'm not making sense Put this in your <head> tag on the page which you want the form displayed: <style type="text/css"> .submit{ background-image:url('link_to_normal_image'); text-indent:-500em; width:140px; /* Adjust as necessary (image size) */ height:30px; /* Adjust as necessary (image size) */ border:0; } .submit:hover{ background-image:url('link_to_hover_image'); } </style> Then replace all first posted code (contact form code) with this: <form name="form1" action="contactformprocess.php" method="POST"> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr bgcolor="#FFFFFF"> <td width="20" height="30"> </td> <td width="113" height="30"> Name</td> <td height="30" width="234" class="text"><span> <input name="name" type="text" id="name" value="" size="20"> </span></td> </tr> <tr> <td width="20" height="30"> </td> <td width="113" height="30"> Location</td> <td height="30" width="234" class="text"><span> <input type="text" name="location" value="" size="20"> </span></td> </tr> <tr bgcolor="#FFFFFF"> <td width="20" height="30"> </td> <td width="113" height="30">Email Address</td> <td width="234" height="30" class="text"><span> <input name="email" type="text" id="email" size="20" maxlength="50"> </span></td> </tr> <tr bgcolor="#FFFFFF"> <td width="20" height="30"> </td> <td width="113" height="0">Comments</td> <td width="234" height="30" class="text"><p name="geff" cols="40" rows="6"><span name="geff" cols="40" rows="6"> <textarea name="comments" cols="40" rows="6"></textarea> </span></p></td> </tr> <tr bgcolor="#FFFFFF"> <td width="20" height="30"> </td> <td width="113" height="30"></td> <td width="234" height="30" class="text"><span> <input type="submit" value="Submit Form" class="submit" /> </span></td> </tr> </table> </form> Andy, you my friend are a diamond It works great, thank you so much, i can try to study it now to see where i was going wrong, it's gonna get exiting when i get to the checkout page soon lol Ok, all i need to do now is sanitise it, I understand replacing $name = $_POST['name']; $email = $_POST['email']; $location = $_POST['location']; $comments = $_POST['comments']; but where do i put function clean($text) { $text=trim(strip_tags(mysql_real_escape_string($text))); //$text = htmlentities($text); // This line is for cleansing HTML emails return $text; } (So, to use this, add the function above to your PHP file) does this mean above the <?php on the php file or put it above the script in the html page?
January 28, 201016 yr Put this: function clean($text) { $text=trim(strip_tags(mysql_real_escape_string($text))); //$text = htmlentities($text); // This line is for cleansing HTML emails return $text; } Immediately after this in your PHP file: <?php Before: /* Email Variables */ It's not a necessity that you put it exactly there, but it keeps it out of the way. Then just replace: $name = $_POST['name']; $email = $_POST['email']; $location = $_POST['location']; $comments = $_POST['comments']; With: $name = clean($_POST['name']); $email = clean($_POST['email']); $location = clean($_POST['location']); $comments = clean($_POST['comments']); EDIT: You don't need the mysql_real_escape_string, sorry: function clean($text) { $text=trim(strip_tags($text)); //$text = htmlentities($text); // This line is for cleansing HTML emails return $text; } Edited January 28, 201016 yr by andyl
Create an account or sign in to comment