Im new to Smarty in combination with PHP and I really like it.
Unfortunatly im running into a problem while validating fields after a $_POST has been done.
I’ve made an array called $errors and use that to save error messages in, for example: $errors[] .= “Wrong email”;.
My problem is in sending the $errors array over to the template so I can use it to display the error messages.
My question: How do you ‘transfer’ the $errors variable over to the template file so you can use it there with, for example {foreach}. I was planning on doing something like
{if $hasErrors}
{foreach from=errors item=error}
<li>{$error}</li>
{/foreach}
{/if}
Thanks in advance
You can assign arrays to your template like you can any other variable.
Also, when building your array initially, drop the concatenation operator and just use:
Finally, be sure to initialize your array before attempting to add elements to it, or assigning it.
EDIT: Now that you’ve included the additional information, I think the problem has to do with your Smarty tag syntax. Try this line instead, adding a
$to your variable: