Hi all!
Believe it or not, and cups of coffee are helping me write this, I've spent all day yesterday and all night trying to get to grips with php. Seemed my brain gathered the concepts pretty quick now I'm confused with all this knowledge. I have to design a contact page with php script on separate page by tomorrow!!!!!!!!!!!!! I seem to find tutorials with php incorporated within the contact page, not separate.
OK - confusion - I know you start with contact page on htm (done in Dreamweaver) and that php.page starting with <?php then I want to make it secure put in all the 'variables?' i.e., details that people have inserted under name,address,email,tel,no etc and chosen radio buttons and from lists etc. and then send neatly by email.
Firstly, I've already got hidden boxes in dreamweaver and also options to pop up if the box isn't filled in, I noticed that php can cover this, so do I omit from dreamweaver? Also what order does what go in i.e., does if($_SERVER ['REQUEST_METHOD']=="POST") {
if (strpos ($_SERVER ['HTTP_REFERER'], $_SERVER ['HTTP_HOST]) 7 II (and what are these two lines?)
come directly after opening, i.e, <?php and before anything else? and where do you put
if (isset ($_POST ['submit'] { within the script - I've looked at so many tutorials but they seem slightly different each time - is it a personal thing????? if the page is saved as contact.php what is the correct action to be put on the contact.htm page (just action = contact.php)??
Many many thanks
Help for a newbie tearing out hair! (please)
Started by HMC, May 10 2007 04:16 AM
3 replies to this topic
#1
Posted 10 May 2007 - 04:16 AM
#2
Posted 10 May 2007 - 06:40 AM
Not sure what you meant in the last part, but why don't you show us your current code and we'll see if we can build upon that.
#3
Posted 10 May 2007 - 10:24 AM
Also, why do you not want the PHP code & the form in one file. Makes it alot easier IMO.
#4
Posted 10 May 2007 - 06:23 PM
I didnt really understand quite what you want but heres how to write a PHP contact form using two separate files and hopefully you can work out what you want to do from this.
Make the outline of your page in index.php coding the banner, footer etc in html and css and in the "content" section write
so it will look something like this:
Then in contact.php write:
Hope that helps, if you need any help with it then PM me but the script has been tested and it works fine.
Make the outline of your page in index.php coding the banner, footer etc in html and css and in the "content" section write
<?PHP require('contact.php') ?>
so it will look something like this:
<!-- W3C header stuffs --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>E-mailing Form</title> </head> <!-- XHTML Body --> <body> <!-- Insert your site framework here including the require where the content is--> </body> </html>
Then in contact.php write:
<?PHP
// Your e-mail address here
$mailto = "blah@blah.bl.ah";
// Start processing the input
// If someone has filled in the e-mail area and submitted the form
if (isset($_REQUEST['email']))
{
// get the e-mail, subject and message from the form. Whilst doing this get rid of any leading or following spaces and get rid of any tags in case they try and Cross Site Script you
$email = trim(strip_tags($_REQUEST['email'] ));
$subject = trim(strip_tags($_REQUEST['subject'] ));
$message = trim(strip_tags($_REQUEST['message']));
// Send the Mail
mail( $mailto, "$subject", $message, "From: $email" ) or die('<p>Failed to Send E-Mail, Please Contact the Webmaster</p>');
echo "<p>Thank you for contacting us, we will be in touch as soon as possible.</p>";
}
else {
// BUT, if no-one has submitted the form - ie a normal page - we will display the form for them
// Enter the page your form is on here: ie index.php
$page = "index.php";
echo "<h1>Contact Form</h1><form method=\"post\" action=\"$page\"><br/><br/><label for=\"email\">E-mail:</label><input name=\"email\" type=\"text\" /><br/><br/><label for=\"subject\">Subject: </label><input name=\"subject\" type=\"text\" /><br/><br/><label for=\"message\">Message:</label><br/><textarea name=\"message\"></textarea><br/><input type=\"submit\" value=\"Send\" /></form>";
}
// End PHP Tag
?>
Hope that helps, if you need any help with it then PM me but the script has been tested and it works fine.
Edited by Case, 10 May 2007 - 06:24 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
