05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

user.template. It uses the {DESTINATION} marker to indicate the script that should process<br />

the form.<br />

Example 13-1. HTML template for user input form<br />

<br />

<br />

User Information<br />

<br />

<br />

Please enter the following<br />

information:<br />

<br />

<br />

<br />

Name:<br />

<br />

<br />

<br />

<br />

<br />

<br />

Example 13-2 shows the template for the thank you page, called thankyou.template,<br />

that is displayed after the user has filled out the form. This page uses the {NAME}<br />

marker to include the value of the user’s name.<br />

Example 13-2. HTML template for thank you page<br />

<br />

<br />

Thank You<br />

<br />

<br />

Thank you for filling out the form,<br />

{NAME}.<br />

<br />

<br />

Now we need a script that can process these template pages, filling in the appropriate<br />

information for the various markers. Example 13-3 shows the <strong>PHP</strong> script that<br />

uses these templates (one for before the user has given us information and one for<br />

after). The <strong>PHP</strong> code uses the FillTemplate( ) function to join our values and the<br />

template files.<br />

Example 13-3. Template script<br />

$bindings['DESTINATION'] = $<strong>PHP</strong>_SELF;<br />

$name = $_GET['name'];<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.<br />

Templating Systems | 299

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!