Re: Full Example of my problem: help with insert (continued)

From: Date: Thu, 03 Jan 2002 07:09:20 +0000
Subject: Re: Full Example of my problem: help with insert (continued)
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2481@lists.php.net to get a copy of this message
afaik only the second version should work: {insert name='get_post_var' variable_name='userName'} the reason it doesent work, is probably because HTTP_POST_VARS does not exist in your function, try adding a global $HTTP_POST_VARS ; in the top of the function. (or try this little example: <? echo $PHP_SELF; echo "<br>"; self(); self2(); function self() {
       echo "self: " . $PHP_SELF;
       echo "<br>";
} function self2() {
       global $PHP_SELF;
       echo "self2: " . $PHP_SELF;
       echo "<br>";
} ?> ) /linus Lawrence Sylvain wrote:
href="file://C:\Program Files\Common Files\Microsoft Shared\Stationery\"> FYI, I've also tried to use a "traditional" get method like shown below. What happens is that the form displays fine with the initial value of "Name from Post" in the input field. But when you click the submit button, and the form re-displays, the value in the Welcome header is still "userName", which is the default returned by the get method. It's as iff the get method doesn't have visibility of the HTTP_POST_VARIABLES.... If I could get this work, I would be very excited. Thank you in advance for any help you may be able to offer. In my .tpl file (you can copy this and past it into a file named tform.tpl and it will run), I have something like:
    <html>
    <head>
    <title>{$title}</title>
    </head>
    <body>
    <center>
    <h1>{$title}</h1>
    {* This is what I really would like to do <h2>Welcome {insert
    $smarty.post.userName}</h2> *}
    {* Since the above doesn't work, I figure, let's try this next
    line... *}
    <h2>Welcome&nbsp;{insert name='get_post_var'
    variable_name='userName'}!</h2>
    <FORM action="{$self}" method=post>
     <INPUT type=input value="{$user_name}" name="userName">
     <INPUT type=submit value="Continue">
    </FORM>
    </FORM>
    </center>
    </body>
    </html>
And in the .php file, I have the following:
    <?php
    require_once('Smarty.class.php');
    $tpl = new Smarty;
    $title = 'Form Demo';
    $template = 'tform.tpl';  // Make sure this matches the name of
    the template file if you decide to run this yourself
    $cache_num = $HTTP_SERVER_VARS["PHP_SELF"];
    if (isset($clear_cache))
    {
        $tpl->clear_all_cache();
    }
    // I've tried this with and without caching with no success
    $tpl->caching = true;
    $user_name='Name From Post';
    $tpl->cache_lifetime = 120; // in seconds
    if ( !$tpl->is_cached($template, $cache_num) )
    {
        $tpl->assign( array(
            'title'        =>    $title,
            'user_name' => $user_name,
            'self' => $HTTP_SERVER_VARS['PHP_SELF']
            ));
    }
     
    $tpl->display($template, $cache_num);
    function insert_get_post_var($args = array('variable_name' =>
    'userName') )
    {
        if ($HTTP_POST_VARS[$args['variable_name']])
        {
            $user_name=$HTTP_POST_VARS[$args['variable_name']] .
    '(from POST)';
        }
        else
        {
            // This is just to demonstrate that the name
            $user_name=$args['variable_name'];
        }
        return $user_name;
    }
    ?>
     
    ----- Original Message -----
    From: Lawrence Sylvain <mailto:LJS@LJSConsulting.com>
    To: smarty@lists.ispi.net <mailto:smarty@lists.ispi.net>
    Sent: Friday, December 28, 2001 9:06 PM
    Subject: [smarty] help with insert
     
          USER: LSYLVAIN CCTR: 91
          JOB: EMLSTY/ID: 822283279
          PR:0.073 IO:0.276 ELPS:1.789
        Does anyone know if there is a way to insert post variables.         I would like to have the page compile just once and be cached,
        but insert "$smarty" variables as needed.  Both of the below
        two examples will get errors.
         
        {insert $smarty.post.myFormVariable}
        {insert {$smarty.post.myFormVariable}}
         
        Thanks in advance for your help!
        With Highest Regards,
        Lawrence
        --------------------------------------------
        Lawrence J. Sylvain
        7023 Manahoac Place
        Gainesville, VA 20155-1645
        LJS@LJSConsulting.com
        http://www.LJSConsulting.com/
        703.754.2593 (Voice)
        703.209.2199 (Cell)
        253.369.8307 (Fax)
        Lawrence J. Sylvain has 15 years of experience in developing
        n-tier/client-server, eCommerce and multimedia solutions for
        small and large organizations. Part of his time and talents
        are devoted to developing new and innovative ways to use
        multimedia, music and networking technologies to spread the
        gospel of Jesus Christ. A printer-friendly resume is available
        at the above web page.
    ------------------------------------------------------------------------
    ---
    You are currently subscribed to smarty as: LJS@LJSConsulting.com
    To unsubscribe send a blank email to
    $subst('Email.Unsub')
    Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/
--- You are currently subscribed to smarty as: linus@mccabe.nu To unsubscribe send a blank email to $subst('Email.Unsub') Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/ --- You are currently subscribed to smarty as: linus@mccabe.nu To unsubscribe send a blank email to $subst('Email.Unsub') Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/


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