print

Form Loader

You are here: C97net5.10 User Preferences

Save & load form values

This feature can save & load form field values.

function save_form ($form_id, $method = 'post')

Save form field values.

$form_id = unique ID.

$method = form method, either GET or POST (default).

function load_form ($form_id)

$form_id = unique ID.

function reset_form ()

Remove saved form. This function automatically called in flush_tpl ().

Notes:

Example 1 test.php

<?php
require './includes/user_init.php';
$cmd = post_param ('cmd');

switch ($cmd)
{
case 'process':
$name = post_param ('name');
$address = post_param ('address');
$details = post_param ('details');

// save the form before proceed
save_form ('myform');

// all fields must be filled
if (empty ($name) || empty ($address) || empty ($details))
msg_die ('echo', 'Please fill all fields');

// reset the form
// usually called in flush_tpl()
reset_form ();

$output = "Name $name<br />Address $address<br />Details $details";
msg_die ('echo', $output);
break;

default:
// load saved form if available
$row = load_form ('myform');

// if form not saved, initialize the values
if (empty ($row)) $row['name'] = $row['address'] = $row['details'] = '';

$tpl = load_tpl ('test.tpl');
$txt['main_body'] = quick_tpl ($tpl, $row);
flush_tpl ();
break;
}
?>

test.tpl

<h1>Welcome to test page!</h1>
<form name="myform" action="test.php" method="post">
    <input type="hidden" name="cmd" value="process" />
    <p>Your name: <input type="text" name="name" value="{$name}"/></p>
    <p>Address: <input type="text" name="address" value="{$address}" /></p>
    <p>Details: <textarea name="details">{$details}</textarea></p>
    <p><input type="submit" /></p>
</form>

 

Posted on: Aug-26-2010 at 07:00am
Last Updated: Jan-01-1970 at 07:00am

There is no comment. Why not be the first?

read more More Comments/Post Your Own

Account

Search

Tags

acp add all also any create default display don download easy echo etc features field file files folder form function includes information init kemana link list may module name need number own page php please qengine read require script set site skin time tpl url use user using version welcome