Variables illustration

The current date and time is September 7th, 2010 8:58:AM

Companion Web Site

Larry Ullman has a web site devoted to PHP for the World Wide Web: Second Edition at this location.

It is intended as a supplement /complement to the book and has many helpful resources.

The Book

Variable image

PHP for the World Wide Web: Second Edition written by Larry Ullman

Chapter 3
Forms

Chapter 3

The form lesson was without much problem at all. In fact all went quite smoothly with this lesson! And, there were so many good pieces of information for now, and for future reference.

Creating a Simple Form

This was easy! the more diffecult challenge came in styling the form. Krisse offered a URL at sitepoint which worked really well...until viewed in IE. So, I went searching and found
Getting Fieldset Backgrounds and Legends to Behave in IE and added it to what I had from sitepoint and solved the problem. The problem was that in IE the color I had chosen for the fieldset background protruded above the form legend. I did have to put a background and borders around the word Form so that the border for the fieldset would not run through it in IE. Here for future reference is a page with 'hacks' for Internet Explorer display bugs. How To Attack An Internet Explorer (Win) Display Bug

I found another site where form layout was done using a list. The problem seems to be, though, that list elements do not belong inside label elements and won't validate. However, they (lists) do make form styling a whole lot easier.
A List Apart

Using GET or POST

I really got a great understanding of the uses and differences between GET and POST. POST provides more security especially when it comes to data such as passwords or credit card numbers because the information is sent directly through the script to the user. With the GET message, all the data is processed through the URL and as such, is displayed.

Receiving Data from a Form in PHP

In many PHP installations, variables can be entered easily for each input element: $name would serve as the input variable for the value,name and so on. But, in my situation, it caused an incomplet form handler response. I had to go to one of the error handling suggestions. I had the Register_Globals problem and went directly to the section on page 60 and solved that. It involved naming variables in this way:
{$_POST['name']}, using the values for the various inputs.

Displaying Errors

By using this line, ini_set ('display_errors', 1); , in your script you can be made a ware of the errors in the script for that page. The 1 means that the display_errors capability is on, for that script. Easier than changing the PHP default which does not display errors, particularly if you don't have administrative control over the PHP.

SUGGESTION: display errors should be turned off for 'live' scripts, its use limited to debugging scripts as you work.

Error Reporting

Turn off all error reporting: error_reporting(0);
Report all PHP errors: error_reporting(E_ALL);
Don't show notices: error_reporting(E_ALL & ~E_NOTICE);

The Register Globals Problem

I needed to use this adjustment and discussed it here.

Manually Sending Data to a Page

This was an interesting exercise in which one needs to enter the information into the address bar which will then place that information on the page.Try it out.

Manually Sending Data

The form for Chapter 3 appears below. Note:at the time of submission, I could not validate the CSS because the CSS servlet kept timing out.

Please complete the form to submit your feedback

The Form















<?php 
/* My Variables for the study group site */
$book "<u>PHP for the World Wide Web: Second Edition</u>";
$author "Larry Ullman";
$myName "Joanne Johnson";
$pageTitle "PHP Study Group ";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $pageTitle ?></title>

<link href="../SpryAssets/ullmanMenu.css" rel="stylesheet" type="text/css" />
<link href="common/ullman.css" rel="stylesheet" type="text/css" />
<link href="feedback.css" rel="stylesheet" type="text/css" />


<script src="../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>

<!--[if IE 7]><link rel="stylesheet" href="common/
fieldsetStyleIe.css" type="text/css" /><![endif]-->

</head>

<body class="thrColHybHdr">

<div id="container">
  <div id="header">
    <h1><?php echo $pageTitle ?></h1>
    <p>Presented by <?php echo $myName ?><br />
    Started January, 2009<br />
    </p>
    <br />
  <!-- end #header --></div>
  <div id="sidebar1">
    <?php include("includes/nav.php"); ?>
    
   
    <p><img src="images/var.jpg" alt="Variables illustration" width="150" height="400" /></p>
    <p>The current date and time is <?php echo date ("F jS, Y g:i:A");?></p>
    
  <!-- end #sidebar1 --></div>
  <div id="sidebar2">
    <h3>Companion Web Site</h3>
    <p>Larry Ullman has a web site devoted to <?php echo $book ?> at this 
    <a href="http://www.dmcinsights.com/phpvqs2/" target="_blank">location</a>.</p>
    <p>It is intended as a supplement /complement to the book and has many 
    helpful resources.</p>
    <ul>
      <li><a href="http://www.dmcinsights.com/phpvqs2/errata.php">Errata</a></li>
      <li><a href="http://www.dmcinsights.com/phorum/list.php?10" target="_blank">Forum</a></li>
      <li><a href="http://blog.dmcinsights.com/" target="_blank">L. Ullman Blog</a></li>
      <li><a href="http://www.dmcinsights.com/bk_pages/faq.php?i=phpvqs2" target="_parent">FAQ</a></li>
      <li><a href="http://de.php.net/manual/en/manual.php" target="_blank">PHP Manual</a></li>
    </ul>
    <p><img src="images/book.jpg" alt="The Book" width="163" height="203" /></p>
    
    <div align="center"><img src="images/var.jpg" alt="Variable image" width="150" height="400" />
      </div>
  <!-- end #sidebar2 --></div>
  <div id="mainContent">
  <center><h3><?php echo $book ?> <span class="spanTitle" >written by</span> 
  <?php echo $author ?></h3>
    <h2>Chapter 3<br />
      Forms</h2>
  </center>
    <!--Script 3.3 -->
<div class="formsection">
  <h3>Chapter 3</h3>
  <p>The form lesson was without much problem at all. 
  In fact all went quite smoothly with this lesson! 
  And, there were so many good pieces of information for now, 
  and for future reference.</p>
  <h4>Creating a Simple Form</h4>
  <p>This was easy! the more diffecult challenge came in styling the form. 
  Krisse offered a URL at 
  <a href="http://www.sitepoint.com/article/fancy-form-design-css/" target="_blank">
  sitepoint</a> 
  which worked really well...until viewed in IE. 
  So, I went searching and found <br />
  <a href="http://www.mattheerema.com/web-design/2006/04/getting-fieldset-
  backgrounds-and-legends-to-behave-in-ie/"
   target="_blank">Getting Fieldset Backgrounds and Legends 
   to Behave in IE</a> and added it to what I 
   had from sitepoint and solved the problem. The problem was that 
   in IE the color I had chosen for the fieldset 
   background protruded above the form legend. 
   I did have to put a background and borders around the word 
   Form so that the border for the fieldset would not run through it in IE. 
   Here for future reference is a page 
   with 'hacks' for Internet Explorer display bugs. 
   <a href="http://www.communitymx.com/content/article.cfm?page=2&amp;cid=C37E0" 
   target="_blank">
   How To Attack An Internet Explorer (Win) Display Bug</a></p>
  <p>I found another site where form layout was done using a list. 
  The problem seems to be, though, 
  that list elements do not belong inside label elements and won't
   validate. However, they (lists) do make 
  form styling a whole lot easier. <br />
      <a href="http://www.alistapart.com/articles/prettyaccessibleforms" 
      target="_blank">A List Apart</a><br />
  </p>
  <h4>Using GET or POST</h4>
  <p>I really got a great understanding of 
  the uses and differences between GET and POST. 
  POST provides more security especially when it 
  comes to data such as passwords or credit 
  card numbers because the information is sent 
  directly through the script to the user. 
  With the GET message, all the data is processed 
  through the URL and as such, is displayed.</p>
  <h4>Receiving Data from a Form in PHP</h4>
  <p>In many PHP installations, variables can 
  be entered easily for each input element:
   $name would serve as the input variable for the 
   value,name and so on. But, in my situation, 
   it caused an incomplet form handler response. 
   I had to go to one of the error handling suggestions. 
   I had <a name="had" id="had"></a>the Register_Globals 
   problem and went directly to the section on page 60  and solved that. 
   It involved naming variables in this way:<br />
    {$_POST['name']}, using the values for the various inputs.<br />
  </p>
  <h4>Displaying Errors</h4>
  <p>By using this line,
    <em>ini_set ('display_errors', 1);</em> , 
    in your script you can be made a
    ware of the errors in the script for that page. 
    The 1 means that the display_errors 
    capability is on, for that script. Easier than 
    changing the PHP default which does not 
    display errors, particularly if you don't 
    have administrative control over the PHP.</p>
  <p>SUGGESTION: display errors should be turned 
  off for 'live' scripts, its use limited 
  to debugging scripts as you work.</p>
  <h4>Error Reporting</h4>
  <p>Turn off all error reporting: error_reporting(0);<br />
  Report all PHP errors: error_reporting(E_ALL);<br />
    Don't show notices: error_reporting(E_ALL &amp; ~E_NOTICE);<br />
    <br />
  </p>
  <h4>The Register Globals Problem</h4>
  <p>I needed to use this adjustment and discussed it <a href="#had">here</a>.</p>
  <h4>Manually Sending Data to a Page</h4>
  <p>This was an interesting exercise in which one needs to enter the information 
  into the address bar which will then place that information on the page.Try it out.</p>
  <p><a href="feedback2.php" target="_blank">Manually Sending Data</a></p>
  <p>The form for Chapter 3 appears below. Note:at the time of 
  submission, I could not validate the CSS because the CSS servlet kept timing out.</p>
  <h4>Please complete the form to submit your feedback<br />
  </h4>
  <form action="handle_form.php" method="post">
    <fieldset>
    <legend>The Form</legend>
    <ol>
   <li> 
   <label>Mr.
    <input type="radio" name="title" id="Mr." value="Mr." />
    </label><br />
    </li>
    
    <li>
    <label>Mrs.
    <input type="radio" name="title" id="Mrs." value="Mrs." />
    </label><br />
    </li>
    <li>
    <label>Ms. 
    <input type="radio" name="title" id="Ms." value="Ms." /> 
    </label>
    </li>
    
    <li>
    <label>Name: <input name="name" type="text" size="20" />
    </label>
    </li>
    
    <li>
    <label> E Mail Address: <input name="email" type="text" size="20" />
    </label>
     </li>
    
   <li> 
   <label> Your response:
    <select name="response">
      <option value="excellent">This is all so excellent!</option>
      <option value="fair">This is very middle of the road.</option>
      <option value="not good">This is the worst I have ever seen!</option>
    </select></label>
    </li>
    
   
  <li>  
  <label> Comments: 
    <textarea name="comments" cols="30" rows="3"></textarea>
    </label></li>
     
      <li>
      <input name="submit" type="submit" value="Send My Information" />
      </li>
      </ol>
    </fieldset>
  </form>
  
  <br />
  <br />
  <br />
  <br />
  <br />
  <br />
  <br />
  <br />
  <br />
  <br />
  <br />
  <br />
</div>
   <!--Script 3.3 -->
   <!-- end #mainContent -->
   <br class="clearfloat" />
  </div>
  <!-- This clearing element should immediately follow the 
#mainContent div in order to force the #container div to 
contain all child floats -->
   <div id="footer">
    <p align="center">&copy;R. Joanne Johnson 2009 </p>
    <p align="center"><a href="http://validator.w3.org/check?uri=referer" target="_blank"><img
        src="http://www.w3.org/Icons/valid-xhtml10"
        alt="Valid XHTML 1.0 Transitional" width="88" height="31" border="0" /></a></p>
  <!-- end #footer --></div>
<!-- end #container --></div>

<div id="sourceDiv">
   <?php  
   
/* shows the source code of the page */
    
show_source(basename($_SERVER['PHP_SELF'])); ?>
    
   <?php  
   
/* shows source for nav bar include */
   
show_source("includes/nav.php");?>
</div>
<script type="text/javascript">
<!--
var MenuBar1 = new 
Spry.Widget.MenuBar("MenuBar1", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
//-->
</script>
</body>
</html>
<ul id="MenuBar1" class="MenuBarVertical">
          <li><a href="/ullmanBook/chapter1.php">Chapter 1</a></li>
      <li><a href="/ullmanBook/chapter2.php">Chapter 2</a></li>
  <li><a href="/ullmanBook/chapter3.php">Chapter 3</a> </li>
  <li><a href="/ullmanBook/chapter4.php">Chapter 4</a></li>
  <li><a href="/ullmanBook/chapter5.php">Chapter 5</a></li>
  <li><a href="/ullmanBook/chapter6.php">Chapter 6</a></li>
      <li><a href="/ullmanBook/chapter7.php">Chapter 7</a></li>
  <li><a href="#">Chapter 8</a></li>
      <li><a href="#">Chapter 9</a></li>
      <li><a href="#">Chapter 10</a></li>
      <li><a href="#">Chapter 11</a></li>
      <li><a href="#">Chapter 12</a></li>
      <li><a href="#">Chapter 13</a></li>
      <li><a href="/ullmanBook/index.php">Home</a></li>
       <li><a href="http://www.lzydaz.com/phpBB3/index.php" target="_blank">Hello World</a></li>
       <li><a href="http://www.lzydaz.com/studygroup/php/index.php" target="_blank">Bonnie</a></li>
       <li><a href="http://www.amaraland.com/studyGroup/index.php" target="_blank">Kc Ladybug</a></li>
       <li><a href="http://krisse.tuna.fi/phpwww/ch1.php" target="_blank">Krisse</a></li>
       
       
    </ul>