HTML and CSS Reference
In-Depth Information
On the PHP side that catches the data, the $_POST array expects the name of the form. Two
variables are i rst declared — $name and $email . Variables in PHP have a dollar-sign ( $ )
prei x. However, before the PHP program attempts to assign the variable with data from the
$_POST array, a good practice is to check the isset() function that checks to see if the
Submit button (named sender ) has sent the data. (h e following code is in formCatcher.
php in this chapter's folder at .)
//Catch HTML5 Data
$name ;
$email ;
if ( isset ( $_POST [ 'sender' ]))
$name = $_POST [ “formName” ];
$email = $_POST [ “formEmail” ];
print $name 's email address is $email ;
Formatting the output using the print statement combines the variables and text in a single
set of double quotes. Within quotation marks, PHP still recognizes variables because the
dollar sign ( $ ) prei x tells the interpreter that, even within quotes, the word is a variable. Most
other languages require concatenation when joining variables and literals. Figure 16-3 shows
both the form as i lled and the output generated by PHP. (Note the localhost address in
the URL window for both the top and bottom panels.)
h at's a simple program, but it does show how PHP passes data from HTML5 to PHP. You'll
also i nd a very interesting result in the e-mail window when you type in something that's not
in e-mail format. You'll i nd that it isn't passed to the PHP module. Instead, it uses the new
HTML5 structure — the e-mail input format — and it acts like a data input validator that
doesn't tell the user that she's messed up.
In order to help users, the HTML5 portion of the application uses an error catcher routine
and informs users that they've made an error in the two parts of the Web page. First, the
e-mail form includes an error handler:
< input type = email size = 32 NAME = ”formEmail” placeholder = ”Enter Name”
onInvalid = ”SendMaster.eLert()” >
Search WWH ::

Custom Search