Older Newer
Tue, 18 Jun 2013 22:30:15 . . . . Tim Fountain [Removed spam]

Changes by last author:

FillInFormValues will fill <input>, <textarea> and <select>/<option> with Smarty template variables and values from $_REQUEST.

For example, you might put something like this in your template:


<form action="{$smarty.server.PHP_SELF|htmlspecialchars}" method="POST">


<ul class="error"><! Validation errors will go here ></ul>

<input type="text" name="first_name"><br/>

<input type="text" name="last_name"><br/>

<select name="state">

<option value="CA">California

<option value="MA">Massachusetts


<input type="submit" value="Submit">




... then do something like this in your PHP code:


$smarty->register_block("fillInFormValues", "smartyFillInFormValues", false);

$smarty->assign("first_name", "Bob");

$smarty->assign("state", "CA");

$_REQUEST['formErrors'] = array();

if (!empty($_POST)) {

// validate form input... Assuming validateForm() returns

// an array of ($formField => "Error message"):

$_REQUEST['formErrors'] = validateForm($_POST);


// Display the form if first time or if there were validation errors:

if (empty($_POST) or !empty($_REQUEST['formErrors'])) {



else {

// process form here...