Re: [SMARTY] Another newbie question: Smarty plugins and forms.
| From: | Jason Sweat | Date: | Sat, 04 May 2002 00:13:32 +0000 |
| Subject: | Re: [SMARTY] Another newbie question: Smarty plugins and forms. | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-4048@lists.php.net to get a copy of this message | ||
Why go to the trouble of making a plugin?
<?php
$t = new Smarty;
$t ->assign(array(
'posted' => $_POST['posted'],
'self' => $_SERVER['PHP_SELF'],
'data' => $_POST['data'] ));
$t->display('test.tpl');
?>
test.tpl:
{if $posted}
you sent {$data}
{else}
<form action="{$self}" method="post">
<input type="hidden" name="posted" value="y">
<input type="text" name="data">
<input type="submit" value="go">
</form>
{/if}
----- Original Message -----
From: "Mieu d'Iscalio Sedai" <mieu@ix.netcom.com>
To: <smarty-general@lists.php.net>
Sent: Friday, May 03, 2002 2:08 PM
Subject: [SMARTY] Another newbie question: Smarty plugins and forms.
> Okay, I want to make a Smarty plugin that displays a form if the user
views
> the page for the first time, but displays the form results otherwise.
>
> Say my plugin is smarty_function_test. This is what I've done.
>
> function smarty_function_test($params, &$smarty)
> {
> empty($firstpass)
> ? show_form()
> : show_results($var1, $var2);
> }
>
> Then in my show_form, which I've put in the same file as
> smarty_function_test, I have something like:
>
> function show_form()
> {
> global $PHP_SELF;
>
> echo <<<FORM
> <form action="$PHP_SELF">
> <input type="hidden" name="firstpass" value="no">
> var1: <input type="text" name="var1"><br>
> var2: <input type="text" name="var2"><br>
> <input type="submit">
> </form>
> FORM;
> }
>
> The show_results function is also in the same file, but its contents are
> irrelevant at the moment. (I just have it echoing some simple message
right
> now.)
>
> In my template file for the page I want to display this form, I just type
in
> {test} to call my plugin. So when a user first loads up the page, he or
she
> gets the form, and fills in whatever values for var1 and var2. Then the
user
> presses submit.
>
> Here's where I run into my problem. $firstpass now has a value, because
the
> hidden input field assigns it one when the form is first displayed. But
> after pressing submit, my plugin just executes show_form again, instead of
> show_results. What should I do to correct this?
>
> Thanks in advance for any help...
> Sally
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>