Another newbie question: Smarty plugins and forms.

From: Date: Fri, 03 May 2002 19:08:46 +0000
Subject: Another newbie question: Smarty plugins and forms.
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4046@lists.php.net to get a copy of this message
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

« previous php.smarty.general (#4046) next »