Design Fundamentals for the Web – Session 9

HTML Forms, PHP & JSON

March 25, 2014

Review

Last week’s agenda

Review of the Web Design Process

  1. Identify the types of users you need to communicate with
  2. Identify what each user type needs to be able to do
  3. Organize your content semantically
  4. Compose appropriate layouts for your content
  5. Create visual hierarchies for your content with type
  6. Apply design principles to emphasize relationships between elements
  7. Create mood and enhance your visual hierarchies and element relationships using color
  8. Breath life into your design with behavioral feedback
  9. Test, rinse & repeat!

HTML Forms

What are Forms?

HTML Forms allow you to capture user input and use it in your application, or pass it on to other applications (e.g. mail servers), or to save it for later use (e.g. in a database or flat file on your server).

Examples of where you might use forms include login forms, contact forms and comment forms.

Form Elements

For more details on the HTML Form Elements, check out W3School's Forms and Input

Demo

Let's experiment with the different Form Elements in a JSFiddle sketch.

Bootstrap's Form CSS Classes

Bootstrap happens to have a number of form styles you can use to spruce up your forms.

Exercise

Using the Elements above, create a basic HTML contact form with a MAILTO: as your form action. Start with your basic Bootstrap template and apply Bootstrap's Form CSS classes to style your form.

You can use this template as a reference.


Introduction to 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
}
?>

Exercise


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.


Assignment 9

Reading

Design

Implement a Contact Page for your Project