GRAF 5016 - Week 6
Today
Php Includes
download the following folder for practice
Open index.html from your basicPhp folder
Create a new external style sheets with the following rules:
* { padding: 0; margin: 0; border: 0; border: 0; outline: 0; font-size: 100.1%; }
body {
font-family:Verdana, Geneva, sans-serif;
color:#666;
background-color: #DEF6FF;
}
#wrapper {
width: 980px;
margin-right: auto;
margin-left:auto;
font-size:12px;
}
back in your index...code view, enter the following after the start of the wrapper div:
<?php include("banner.php"); ?>
Style your banner:
#banner {
background-image: url(images/8012_Industrial_Sabotage.jpg);
background-repeat: no-repeat;
height: 275px;
background-position: center -75px;
}
now your nav include (after the banner):
<?php include("nav.php"); ?>
style your nav:
#nav {
background-color: #CCC;
padding: 15px;
text-align: center;
}
#nav a {
display: block;
width: 150px;
font-size: 12px;
font-weight: bold;
color: #FFF;
background-color: #4C49A0;
padding: 10px;
text-decoration: none;
float: left;
margin-left: 17px;
Lastly, add your footer after the content div:
<?php include("footer.php"); ?>
and style it:
#footer {
background-color: #CCC;
padding: 5px;
clear: both;
text-align: center;
}
#footer a {
font-size: 8px;
color: #4E499F;
}
and some additional styles:
#content {
padding: 30px;
background-color: #FFF;
}
.clearBoth {
clear: both;
}
that's it - look at how little html code you have! This will make updating your site more efficient.
Simple Php Form
ACTION:
The html FORM element has one required attribute, ACTION - which specifies the URL of the script that will process the form's data.
METHOD:
The PHP $_GET & $_POST variables are used to get the values which are passed from a user-filled form, like user registration or login form etc.
$_GET is less secure and effective than $_ POST, $_GET has few limitations like it can send about 100 words of data at a time, whereas $_POST does not have such kind of limitations, we can send any amount of data using this variable. $_GET is less secure because when we send data from one web page to another using $_GET, we can see the values in address bar, on the contrary $_POST does not allow any thing to be displayed in address bar of the browser.
When to use method="get"?
Note: This method should not be used when sending passwords or other sensitive information!
When to use method="post"?
In your exisiting page, or you can create a new one if you like, enter the following code to create an html form:
<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
Here's how your form will look:
Now we need to process that data...
Create a new php page, and save it as welcome.php
Add the following code to the body of the welcome page:
Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.
The "welcome.php" file uses the $_POST function to collect form data (the names of the form fields will automatically be the keys in the $_POST array).
Post your site in your Sites folder on the server....and then test!
Creating a Php E-mail Form
Here is the html code for the form:
<form action="process.php" method="post">
First Name:<input type="text" name="fname" />
Last Name: <input type="text" name="lname" />
E-mail: <input type="text" name="email" />
<select name="item">
<option>Paint</option>
<option>Brushes</option>
<option>Erasers</option>
</select>
Quantity: <input type="text" size="5" name="quantity" />
<input type="submit" />
</form>
It should look something like this:
Order Form
Now we'll create the code to process the form
Create a new php page, save it as process.php
<?php
//variables
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$item = $_POST['item'];
$quantity = $_POST['quantity'];
?>
Thank you for your order <?php echo "$fname";?>
<?php
// Contact subject
$subject ="Online Order";
// Email message content
$message="$fname $lname has ordered: \n $quantity $item";
// Mail of sender
$email="$email";
// From
$header="from: $fname $lname $email";
// Enter your email address
$to ='nmccrave@rogers.com';
$send_contact=mail($to,$subject,$message,$header);
?>
test it!