Design Fundamentals for the Web – Session 10

More HTML Forms, PHP & JSON

April 1, 2014

Review

Last week’s agenda

Review of PHP

What is PHP?

PHP stands for PHP Hypertext Preprocessor, and is a server-side programming language developed specifically for the web, although it can be used as a more general-purpose server-side scripting language as well.

Web Server Access

To use PHP, you'll need access to a web server. If you haven't set up your TCNJ web hosting account yet, you can follow these instructions to do so. There are also many alternative hosting services available were you can gain access to your own web server. Ask your friends & classmates for suggestions if you're interested in outside hosting.

FTP

Once you have web server access, you'll need FTP software to transfer your files to your server. FTP stands for File Transfer Protocol and can be used to copy files from your local computer to your web server.

Using PHP

PHP has a similar syntax to Javascript and C, but has some unique features as well. Let's go ahead and demonstrate some of the features of PHP.

<?php
/*
This is a multi-line comment in PHP,
the same as in Javascript & CSS.
*/

// here's a single line comment like in Javascript as well


// like Javascript, PHP variables are "loosely" typed
$myString = "a text string";
$myInteger = 10;
$myDecimal = 3.14159;
$myIndexedArray = [1,2,3,4];
$myAssociativeArray = ['firstname'=>'','lastname'=>'', 'email'=>''];

if(!empty($myAssociativeArr["email"])){
// do something if it's true
} else {
// do something else if it's false
}
?>


Introduction to JSON & Ajax

What is JSON?

JSON stands for Javascript Object Notation and is becoming a widespread alternative to XML as a data exchange format. Many web services including Facebook, Twiiter and Yahoo use JSON as their return data format for their APIs (Application Programming Interfaces).

jQuery has a number of functions that will let us call other scripts, either on our server, or on remote servers like Twitter, Yahoo, or even tcnj.com. Using these functions, we can access our PHP scripts remotely, allowing us to host our HTML on Github Pages, but execute server-side logic on other servers. This is called Cross Site Scripting, and used to be (and can still be) considered a security threat, but is becoming an increasingly common way of delivering content through APIs.

Demo

Let's take a look at some example jQuery JSON Ajax code and see it in action.

You can also find both the HTML and the PHP code at this Github repositiory.

Exercise

Create an Ajax/JSON-enabled Contact Form in Github


Assignment 10

Reading

Design

Prepare your site for initial Design Review and User Testing