Last Week:
- Najlah
- Rashida
- Ara
- Chris
- Jae Hwan
- Tyler
TODAY:
- Lev
- Miliam
- Yelena
- Andre
- Ji Young
In order to process the information submitted by a user to a form on your site, you need a way to capture that data. Because HTML, CSS, and JavaScript all happen on the client-side, and can’t send information back to the browser, you need something like PHP, working on the server side, to do this. We’re going to go over two very simple form processing scripts today.
The first example is for sending the results of a form as an email.
To invoke the PHP code you are going to use to process the form, you are going to submit the form to a .php page. This is accomplished by setting the form action to the name of the page:
<form action=”email_form.php” method=”post”>
Next, you are going to create a .php file to process the form contents. In this example, we are going to name this script email_form.php
By submitting our form to this script, the values from the form are passed to it. These values are automatically stored in an array called $_POST. We can now access the values in this array, and the first thing we need to do is to make them easier to work with://Change post variables to regular variables
$ipod = $_POST['ipod'];
$laptop = $_POST['laptop'];
$cell_phone = $_POST['cell_phone'];
$borough = $_POST['borough'];
Note that the values between the brackets [’…’] match the names of the inputs you passed from your form.
The next thing you need to do is turn all these values into a single string so it can be emailed:
//Turn all the variables into a single string.
//Note: .= appends to the current variable value rather than replacing it
$formresults = "Ipod: ".$ipod."\n";
$formresults .= "Laptop: ".$laptop."\n";
$formresults .= "Cellphone: ".$cell_phone."\n";
$formresults .= "Borough: ".$borough;
Next, you will use the built-in function called mail to email the form results to the designated email:
//send values as email
mail("youremail@domain.com", "Form Results from Web site", $formresults, "From: youremailhere@yourdomain.com");
Now, it’s good practice to give your visitors a confirmation message so they know their information was submitted://print opening html
print("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">
<html>
<head>
<title>Form Example</title>
<meta name=\"generator\" content=\"BBEdit 8.2\">
</head>
<body>");
//Print confirmation message to the screen
print("Your answers have been emailed to our secret headquarters. Thanks for playing!");
//print closing html
print("</body>
</html>");
Last, don’t forget to close your php tag:?>
Say instead of emailing your results you just want to store them in a file on your server. This example shows you how.
Your form file remains the same, but for the purpose of this example, we are going to change the action to this:<form action=”file_form.php” method=”post”>
This time we are processing the form with a php script called file_form.php
The beginning of this script is identical to the previous example.
//Change post variables to regular variables
$ipod = $_POST['ipod'];
$laptop = $_POST['laptop'];
$cell_phone = $_POST['cell_phone'];
$borough = $_POST['borough'];
//Turn all the variables into a single string.
//Note: .= appends to the current variable value rather than replacing it
$formresults = "Ipod: ".$ipod."\n>";
$formresults .= "Laptop: ".$laptop."\n";
$formresults .= "Cellphone: ".$cell_phone."\n";
$formresults .= "Borough: ".$borough;
This time, however, you are going to use a number of functions that are designed to handle opening, writing, and closing files on the server.
//this code is adapted from Example 1 at http://us3.php.net/manual/en/function.fwrite.php
//identify the file
$filename = "formdata.txt";
//see if the file exists and is writable
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// the function fopen opens the specified file. The 'a' argument opens the file in append mode
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $file to our opened file.
if (fwrite($handle, $formresults) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
//close the file
fclose($handle);
} else {
echo "The file $filename is not writable";
exit;
}
The last thing you need to do is create the text file. Open up a text editor and save a blank document as formdata.txt. Upload it to your site. You may need change the file permissions in order for the script to work right. The permissions should be 666, readable and writeable by everyone.
In order to process the information submitted by a user to a form on your site, you need a way to capture that data. Because HTML, CSS, and JavaScript all happen on the client-side, and can’t send information back to the browser, you need something like PHP, working on the server side, to do this. We’re going to go over two very simple form processing scripts today.
The first example is for sending the results of a form as an email.
To invoke the PHP code you are going to use to process the form, you are going to submit the form to a .php page. This is accomplished by setting the form action to the name of the page:
<form action=”email_form.php” method=”post”>
Next, you are going to create a .php file to process the form contents. In this example, we are going to name this script email_form.php
By submitting our form to this script, the values from the form are passed to it. These values are automatically stored in an array called $_POST. We can now access the values in this array, and the first thing we need to do is to make them easier to work with://Change post variables to regular variables
$ipod = $_POST['ipod'];
$laptop = $_POST['laptop'];
$cell_phone = $_POST['cell_phone'];
$borough = $_POST['borough'];
Note that the values between the brackets [’…’] match the names of the inputs you passed from your form.
The next thing you need to do is turn all these values into a single string so it can be emailed:
//Turn all the variables into a single string.
//Note: .= appends to the current variable value rather than replacing it
$formresults = "Ipod: ".$ipod."\n";
$formresults .= "Laptop: ".$laptop."\n";
$formresults .= "Cellphone: ".$cell_phone."\n";
$formresults .= "Borough: ".$borough;
Next, you will use the built-in function called mail to email the form results to the designated email:
//send values as email
mail("youremail@domain.com", "Form Results from Web site", $formresults, "From: youremailhere@yourdomain.com");
Now, it’s good practice to give your visitors a confirmation message so they know their information was submitted://print opening html
print("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">
<html>
<head>
<title>Form Example</title>
<meta name=\"generator\" content=\"BBEdit 8.2\">
</head>
<body>");
//Print confirmation message to the screen
print("Your answers have been emailed to our secret headquarters. Thanks for playing!");
//print closing html
print("</body>
</html>");
Last, don’t forget to close your php tag:?>
Say instead of emailing your results you just want to store them in a file on your server. This example shows you how.
Your form file remains the same, but for the purpose of this example, we are going to change the action to this:<form action=”file_form.php” method=”post”>
This time we are processing the form with a php script called file_form.php
The beginning of this script is identical to the previous example.
//Change post variables to regular variables
$ipod = $_POST['ipod'];
$laptop = $_POST['laptop'];
$cell_phone = $_POST['cell_phone'];
$borough = $_POST['borough'];
//Turn all the variables into a single string.
//Note: .= appends to the current variable value rather than replacing it
$formresults = "Ipod: ".$ipod."\n>";
$formresults .= "Laptop: ".$laptop."\n";
$formresults .= "Cellphone: ".$cell_phone."\n";
$formresults .= "Borough: ".$borough;
This time, however, you are going to use a number of functions that are designed to handle opening, writing, and closing files on the server.
//this code is adapted from Example 1 at http://us3.php.net/manual/en/function.fwrite.php
//identify the file
$filename = "formdata.txt";
//see if the file exists and is writable
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// the function fopen opens the specified file. The 'a' argument opens the file in append mode
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $file to our opened file.
if (fwrite($handle, $formresults) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
//close the file
fclose($handle);
} else {
echo "The file $filename is not writable";
exit;
}
The last thing you need to do is create the text file. Open up a text editor and save a blank document as formdata.txt. Upload it to your site. You may need change the file permissions in order for the script to work right. The permissions should be 666, readable and writeable by everyone.
var beatles = Array(4);
beatles[0] = "John";
beatles[1] = "Paul";
beatles[2] = "George";
beatles[3] = "Ringo";
the syntax is working like this:
var name_of_array = Array(length);
name_of_array[index] ="value_of_this_element";
var beatles = Array(); // notice that the length can be left blank if you want
beatles[vocalist] = "John";
beatles[Rhythmguitar] = "Paul";
beatles[bass] = "George";
beatles[drummer] = "Ringo";
var beatles = Array(); // notice that the length can be left blank if you want
beatles[vocalist] = lennon;
beatles[Rhythmguitar] = mccartney;
beatles[bass] = harrison;
beatles[drummer] = star;
var lennon = Array();
lennon[firstname] = "John"; //notice that the value of these elements can be
lennon[birthyear] = 1940; //numbers
lennon[living] = false; //or boolean values
var year = 2005;
var message = "the year is";
message += year;
alert (message);
var mood = "happy";
var message = "I am feeling"+mood;
if (condition){
statements;
}
for example:
if (1>2) {
alert("the world has gone made");
}
if(1>2){
alert("the world has gone mad!!!!! OMG!!!!");
}
else {
alert("everything is fine, chill out");
}
while (condition){
statements;
}
var count = 1;
while (count < 11) {
alert(cont);
count++;
}
do{
statements;
} while (condition);
for (initial condition; test condition; alter condition){
statements;
}
example:
for (var count =1; count < 11; count++){
alert (count);
}
and a more complex example:
var beatles = Array("John","Paul","George","Ringo");
for (var count=0; count < beatles.length; count++){
alert(beatles[count]);
}
function name(arguments){
statements;
}
example:
function multiply(num1, num2) {
var total = num1 * num2;
alert(total);
}
multiply(10,2);
function convertToCelsius(temp) {
var result = temp -32;
result = result / 1.8;
return result;
}
var temp_farhenheit = 95;
var temp_celcius = convertToCelsius(temp_fahrenheit);
alert(temp_celsius);
document.getElementById(id);
document.getElementByTagName(tag);
object.getAttribute(attribute);
var paras = document.getElementByTagName("p");
for (var i=0; i < paras.length; i++){
alert(paras[1].getAttribute("title"));
}
object.setAttribute(attriute,value);
//comments look like this
// and need slashes on each line
/*unless
you do this */statement;
statement;
statement;
//comments look like this
// and need slashes on each line
/*unless
you do this */
div.projectsimg {
float:left;
width:236px;
height:79px;
background-image:url(images/shadow.png);
background-repeat:no-repeat;
margin:0px 25px 10px 14px;
padding:0px 0px 12px 12px;
background-position:12px 3px;}
======================|Overview|======================
This estimate includes the details for designing and implementing an elegant and
beautiful website for the Drawing on Film exhibition including a blog, an interactive
flash home page module, and multimedia info about the artists and works included in
the exhibition. The lead designer will be Catherine (Katy) Garnier, a multimedia artist
with a particular passion for and knowledge of the history of direct film including
many of the artists in the exhibition. The design will express the spirit of the
exhibition and be a key communication tool for the drawing center and subsequent
venues. The site will allow DC staff to maintain the site and upload new content
through WordPress. Our numbers are based on our hourly rates of $100/hr for
design and WordPress php coding.
===================|Technical Standards|==================
The web site will conform to current best practices and standards for professional
quality web sites. It will be optimized for the latest versions of Microsoft Internet
Explorer, Safari, and Firefox along with the latest version of the Flash plug-in. It will
also maintain a consistent appearance (to the extent practicable) on both the Mac
and Windows platforms.
div.projectsimg {
float:left;
width:236px;
height:79px;
background-image:url(images/shadow.png);
background-repeat:no-repeat;
margin:0px 25px 10px 14px;
padding:0px 0px 12px 12px;
background-position:12px 3px;}
CLIENT WORK
TECHNICAL PREPARATION
For next class:
CLIENT WORK
Skills practice and Reading
Advanced Web Design
CRN 3053
Spring 2008
Instructor: Jay Van Buren
Email: ad650@early-adopter.com
Course URL: http://vanburen-adv-web.blogspot.com/
Hours: Thursday, 9:00 - 11:40
Location: 55 W. 13th, Rm. 425
Course Description:
The Web may be a turning point in human history that rivals the taming of fire or the invention of the printing press. It's been changing profoundly how we do business and communicate for the past 10 years and its just getting started. New technologies are ensuring that as the haystack of information grows exponentially our ability to find the needle we need at any particular moment is growing too.
Whether you are selling a product or service, trying to convince people of an idea, or creating interactive art, the web is the air we all breathe. Understanding how to use this medium as well as it can be used will help your (or your client's) content stand out both now and in the future.
The main projects will be the completion of a website for an actual client, including all the stages that a professional web designer should go through on the way to creating the site. This class is not about learning to create websites (you should already know that). This class is about creating truly excellent, beautiful, elegant websites that are built using the best possible practices, and match the needs of your client in both form and function. We'll also spend some time talking about and trying to understand both where we are right now and where we are headed.
Course Goals:
Upon successful completion of this class, the student will have gained the skills be a professional web designer, and will have a thorough grasp of the state of the art of web design including both aesthetic, conceptual and technical issues.
Grading:
10% - Attendance and Class Participation
40% - Weekly Assignments (each one will be worth 6 points 6=excellent, 5=average, 4=acceptable, not turned in = 0)
50% - Final Project
Course Requirements:
Reading and Resources:
There are two texts that we'll be reading from