Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

array only printing the first letter of the value

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
coolriree5
Smarty Rookie


Joined: 25 Jun 2009
Posts: 7

PostPosted: Fri Jun 26, 2009 8:12 am    Post subject: array only printing the first letter of the value Reply with quote

hello my array is only printing out the first letter from the value.

this is my array

Code:

Array ( [posts] => Array ( [collar] => 56856877 [password] => ) [microsite] => Array ( [id] => [wdtsiteloggedin] => 1 [collar] => [email] => [firstname] => [lastname] => [rank] => ) [form_errors] => Array ( [0] => Array ( [errordiv] => collar_error [errormessage] => Please enter a valid collar number ) [1] => Array ( [errordiv] => password_error [errormessage] => Please ensure the field is filled out correctly ) ) )



this is my smarty loop




Code:

{foreach from=$smarty.session.form_errors item=error}
 {foreach from=$error item=item key=key}
 {$item.errordiv}
  {if $item eq "collar_error"}
  {*<li>{$item}</li>*}
  {/if}
 {/foreach}
{/foreach}


and my result is


c P p P

however if i print out the item i get both the keys and the values

any suggestions of where i am going wrong in the loop?

thanks for the help in advance Very Happy
Back to top
View user's profile Send private message
coolriree5
Smarty Rookie


Joined: 25 Jun 2009
Posts: 7

PostPosted: Mon Jun 29, 2009 9:03 am    Post subject: Reply with quote

RESOLVED

Code:

{foreach from=$smarty.session.form_errors item=item key=key}
 {if $item.errordiv eq "password_error"}
  {$item.errormessage}
 {/if}
{/foreach}


hello for those interested when using the $item.property method of looping, if you try to access the property too deep into the foreach (meaning you are using too many foreach loops) you will be returned with the first letter of each item

Thanks for all that looked at this

Nicholas
[/u]
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Jan 13, 2010 8:17 pm    Post subject: Reply with quote

If you are only getting the first character you are accessing a string and not an array.
The reason "because it's nested too deep" is wrong here.
You should have used $error.errordiv and not $item.errordiv and you would only needed one foreach and not two nested ones.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP