>> DAVID MALAN: Let's create a website via which freshmen can register for
intramural sports.
In particular, let's create a form on a web page that asks for their name,
for their gender, for their dorm, as well as whether or not they'd like to
be a team captain.
Let's take a look.
>> In advance, I've already gone ahead and created this form here.
It's not the prettiest thing in the world, to be sure, but it does ask for
all of those details.
Let's go ahead and now take a look at the underlying source.
In froshim-0.php, notice that I actually have entirely HTML.
It turns out that a PHP file doesn't strictly need to contain PHP, but if
it does, it will be executed by the interpreter so long as it's in between
the open PHP tag and close PHP tag.
>> Notice then that we have really the essence an HTML form here.
We have the form tag, as expected.
We have an input here, whose name is name and whose type is text, for the
undergraduates name.
>> We have here another input that's of type check-box in order to allow him
or her to specify whether or not they'd like to be a team captain.
Then we have two inputs, both whose name is gender, both of whose type is
radio but which have different values, F for female and M for male.
It turns out that radio buttons can be designed in this way to be mutually
exclusive so that if we check male, that unchecks female, and if we check
female, that unchecks male.
>> Meanwhile, if we proceed to look below dorm, we see that there's a select
menu, inside of which is quite a few options.
The first of those options has no value.
It's simply meant to ensure that the menu is indeed blank by default for
the student's dorm.
Below that, we have options for Apley Court, for Canaday, and every other
freshman dormitory.
Now down below this select menu, notice we have a final input, this one
of type submit, whose value or label is register.
>> So now let's take a look at the file to which this form
is going to be submitted.
How to know where it's being submitted--
well if we scroll back up higher in the file, notice that the form tag had
an action attribute of register-0.php, and the form will be submitted to that
page via the HTTP method post.
Let's now take a look then a register-0.php.
>> In register.php, we again have mostly HTML.
But inside of the body, notice this.
There's a pre tag which denotes preformatted text, text that should be
rendered in a monospaced font.
And then inside that pre tag, notice that we have here a PHP tag, open and
close, and a call to a function called print_r, which prints recursively
whatever you pass in as its argument.
>> In this case, I'm passing in recursively a superglobal variable
called $_post.
It's in this superglobal, this associative array, that any HTTP
parameters or form fields that were submitted by the user will end up for
us to access.
Let's now take a look in a browser at froshim-0.php.
>> Let's go ahead and register myself as David Malan.
I'll be a captain, and I'll be a male in, say, Matthews.
Let's now click Register.
>> And now, notice we see hideous result.
But this is simply the result of printing in preformatted text-- that
is, a monospaced font--
the contents of that associative array.
In particular, notice that what the browser ultimately submitted to the
server is a name whose value is David Malan; a field called captain, whose
value is apparently on, which seems to be the default value when I check a
check-box; gender, whose value is M for male; and dorm,
whose value is Matthews.
Now I haven't yet done anything with these values.
But clearly, because PHP is bundling them up for me in this superglobal
called $_post, I'll surely have programmatic access to do something
with those variables, like register this freshman.