Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8672255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:09:28+00:00 2026-06-12T19:09:28+00:00

Im new to Smarty in combination with PHP and I really like it. Unfortunatly

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:09:30+00:00Added an answer on June 12, 2026 at 7:09 pm

    You can assign arrays to your template like you can any other variable.

    $smarty->assign('errors', $errors);
    

    Also, when building your array initially, drop the concatenation operator and just use:

    $errors[] = 'Wrong email';
    

    Finally, be sure to initialize your array before attempting to add elements to it, or assigning it.

    $errors = array()
    

    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:

    {foreach from=$errors item=error}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SOLVED: Error in template file I have Smarty setup like this: require_once 'smarty/Smarty.class.php'; $smarty
I have this php code: $db = new mysql; $new_bad = $_POST['new_bad']; $new_replace =
I'm sending one of my object to smarty like $smarty->assign('test', new MyObject ) ;
I am using the following code require 'Smarty/libs/Smarty.class.php'; $smarty = new Smarty; $sel=mysql_query(select id,
I really like the smarty documentation but sometimes its hard to find easy stuff...
I have a pretty simple question but I am really new to php. I
Hey, I'm trying to do something like this: <?php class MySmarty extends Smarty {
Darn. Facing problem while outputting some variables in Smarty templates. Hope some one could
I have problem with WPF - I'm quiet new in this smart technology. So
New to PHP and MySQL, have heard amazing things about this website from Leo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.