2

the foreach method is not working properly in the smarty template engine. Can you show how it might look using a while loop

// Foreach data in post array saved : add a new input in the redirection form
foreach($_SESSION['POSTDATA'] as $key => $value)
{
    if($key!='ACTION' && $key!='AES_KEYS')
    {
        $smarty->assign('postdata',array('id' => $key, 'name' => $key, 'value'  => $value));
    }
}
$_SESSION['POSTDATA'] = '';

1 Answers1

0

As per your code, you could try this to be correct (since you're trashing the previous 'postdata' value at each loop iteration and want to exclude ACTION and AES_KEYS keys):

unset($_SESSION['POSTDATA']['ACTION']);
unset($_SESSION['POSTDATA']['AES_KEYS']);
$smarty->assign('postdata', $_SESSION['POSTDATA']);

Then you can access your 'postdata' variable assigned to smarty using this:

{$postdata.yourkey}

Anyway you could directly access the session global using this in smarty 3:

{$smarty.session.POSTDATA.desiredkey}

or this

{$smarty['session']['POSTDATA']['desiredkey']}
Juanga Covas
  • 315
  • 2
  • 5