Task 1: Process a form

Comment was:

Default comment.

The form:

comment
option use option if checked.
 

Index | Next»

Questions? csnyder@chxo.com

Source of this script

<?php
// initialize template
include_once('libs/Smarty.class.php');
$template= new Smarty;
$template->assign('title''Task 1: Process a form');
$template->assign('next''task1-alt-smarty.php');


    
// TASK: display and/or process a form
    
$comment'Default comment.';
    
$option0;

    
// process
    
if ( isset ( $_REQUEST['submit'] ) ) {
        
$comment$_REQUEST['comment'];
        
$option$_REQUEST['option'];
    }

// assign the values to the template
$template->assign('comment'$comment);
$template->assign('option'$option);

// display the template
$template->display('task1.tpl');
?>

<h3>Source of this script</h3>
<?php
$output
highlight_file($_SERVER['SCRIPT_FILENAME'],1);
print 
$output;
?>

<h3>Source of the template</h3>
<?php
$output
highlight_file(dirname($_SERVER['SCRIPT_FILENAME']).'/templates/task1.tpl',1);
print 
$output;
?>

Source of the template

{* Smarty: task 1 template *}
{include file="header.tpl"}

<h3>Comment was:</h3>
<blockquote>{$comment|escape}</blockquote>
{if $option eq 1}<p>Option was checked.</p>{/if}

<form action="" method="post">
<h3>The form:</h3>
<table class="edit">
    <tr>
        <td class="label">comment</td>
        <td><input type="text" name="comment" size="56" value="{$comment|escape}" style="padding: 3px;" /></td>
    </tr>
    <tr>
        <td class="label">option</td>
        <td><input type="checkbox" name="option" value="1" {if $option eq 1}checked="checked"{/if} /> use option if checked.</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td><input type="submit" name="submit" value="submit" /></td>
    </tr>
</table>
</form>

{include file="footer.tpl"}