Wednesday, November 4, 2009

Invariably Passing...

Today we are learning to pass a variable from one PHP page to the next. Specifically, we are setting up a straight HTML form on the first page ("formtest.php") and sending the information to a second page ("formdisplay.php") when the user clicks "submit."

We created the the first page (the form, named "formtest.php") in Dreamweaver and used the point-and-click Design view interface to create the form (no coding needed). See form layout below:


Be sure to set the properties for various items as well as detailed below:
  1. To create the form (the form is indicated by the red dotted line), click Insert >> form >> form.
  2. Accept form1 as the name of the form; set the "action" of the form to be formdisplay.php
  3. Set the method to "GET." (see picture below)



  4. To insert the name field, click Insert >> Form >> Text Field. Set "Name" to "name," "Char Width" to 25 and "Max Chars" to 50. Be sure to put the text field INSIDE the form, i.e, the red dotted line.
  5. Insert the submit button: Click Insert >> Form >> Button. Accept the default name, etc. and press OK.
  6. Insert the reset button: Click Insert >> Form >> Button. Accept the defaults. Change the "action" for the button to "Reset form."
  7. Save the page.
Open "formdisplay.php" and enter the following code to display the output of the form from formtest.php:


To test the code, open formtest.php on our class webserver, type a name, and press submit. The name should display on the page called "formdisplay.php."

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.