CS371, Fall 2001
Lab 2: PHP and Forms

We have been looking at how PHP variables are used to represent data from HTML forms. A sample form that uses several different types of input elements can be found in the file form.html. (For the source code, click here.) You also have the sample php file, prod.php, which we looked at in class. (For the source code, click here.) In this example, the php file serves as both the main page that first presents the form to the user and as the script that processes the data from the form.

In today's lab, you should start working on an HTML form that collects data for a survey and a PHP script that processes that data. It would make a great deal of sense to use a single php file for both purposes, as was done in the prod.php example. The form must include at least ten input elements of various types, including text box, radio button, checkbox, and <select> menu. Some of these inputs should be marked as "required."

When your script receives the data, it should check whether all the required inputs have been filled in. If not, it should redisplay the form -- with all the data that the user has entered. (You can check the source code for the form in prod.php to see how this is done.) If all the required data was entered, you should simply display all the data from the form on a Web page. Later in the course, you will store the survey data in a database and write another script that can be used to check the results of the survey.

Your survey can be about any topic you like. If you can't think of anything else, make it a course evaluation form.

The survey should be stored in your public_html directory. Put a clearly marked link from your main page to the survey. The assignment should be complete by next Wednesday, September 13, at the beginning of class. Turn in a printout of your php script. Try to make your pages look reasonably nice and well-organized in a Web browser. Follow the rules of good programming style in your script. For example: include comments, as you would in any program; use meaningful variable names; and indent your program to display its structure.

Some Fun with PHP and CSS

Try reloading this page a few times. The colors and margins on this page are set by a CSS style sheet, which is actually generated by a PHP script. The script will output one of four different style sheets, at random. PHP is not limited to outputting HTML. It can output any kind of HTTP response. If you want to see the source code of the script, click here.

Alternative Log-in Methods

Since X-Win32 is probably still not configured in the labs, you might want to know about two alternative set-ups for logging on to one of the cslab computers. If you see the "X-Win32 session set-up wizard" when you start X-Win32, you can:

Enter one of the cslab computer names (cslab1, cslab2, ..., cslab9) in the "Host Name" box and click "Next". (Currently, cslab7 is not available.) Click on "XDMCP" and click "Next". Click "Query" and click "Next". Enter any random name for the session, click the "Launch this session now" checkbox, and click "Finish". You should get a Linux log-in screen.

Alternatively, you can use the "rexec" login method instead of "XDMCP". You won't get a KDE desktop, but you'll get a command-line window. Interestingly, the Linux program windows that you open will be mixed in with your Windows windows. To use this method in the X-Win32 session set-up wizard: Enter one of the cslab computer names (cslab1, cslab2, ..., cslab9) in the "Host Name" box and click "Next". Click on "rexec" and click "Next". Enter your Linux user name and password and click "Next". The default entries on the next screen are OK; just click "Next". Enter any random name for the session, click the "Launch this session now" checkbox, and click "Finish". You should get a terminal window where you can type in commands.

Two Configuration Notes

When you start up nedit, you might see a message in the console window saying that your .nedit file is for an old version of nedit. This is because we have installed a new version of the program. To fix the error, just go to the "Preferences" menu in nedit and select the "Save Defaults" command. This will make a new .nedit file in your home directory.

I might send email to you at your @hws.edu address. If you do not read mail sent to this address, it would be a good idea to have your mail forwarded to an account that you do use. To set up mail forwarding, you have to telnet to the computer hws3.hws.edu. You can do this from your Linux account with the command "telnet  hws3". (If you don't know your hws3 password, you will have to check with the people at Williams Hall. Initially, at least, it was the same as your Windows password.) Once you are logged on to hws3, type in the command "mail". You will see a MAIL> prompt. At this prompt, enter "set  forward  <email-address>", where <email-address> is the address to which your mail is to be forwarded. You can then exit from the mail system by entering "exit" and log off from hws3 with the command "logout". You should send an email to your @hws.edu address, to make sure that it is forwarded properly.

David Eck (eck@hws.edu), 7 September 2001