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

does the append function attribute work

 
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 -> Add-ons
View previous topic :: View next topic  
Author Message
pabianjs
Smarty Rookie


Joined: 28 Jun 2004
Posts: 6

PostPosted: Mon Jun 28, 2004 9:53 pm    Post subject: does the append function attribute work Reply with quote

first thanks again mont.. good stuff

im using the 2.2-b1 of SmartyValidate

im assigning error messages to appError via the append function attribute

{ ..... message="helo", append=appError }

the smarty debug template shows the variable assigned to the template but the template variable fails when used as a conditional to smarty's IF or in a smarty section tag..

{if $appError}
{section=i name=appError}
<li>{$appError[i]}
{/section}
{/if}

the default error reporting works fine.. any thoughts before i dig around

jp
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jun 29, 2004 2:17 am    Post subject: Reply with quote

$appError is going to be an array of values, you're testing it like a boolean.

You need to do something like:

{if !empty($appError)} ... {/if}

or,

{section=i name=appError}
<li>{$appError[i]}
{sectionelse}
its empty...
{/section}
Back to top
View user's profile Send private message Visit poster's website
pabianjs
Smarty Rookie


Joined: 28 Jun 2004
Posts: 6

PostPosted: Tue Jun 29, 2004 9:24 pm    Post subject: append now working Reply with quote

the validator tags must be called prior to using the assign or the append function attribute

{$app_error}
{validate....... assign='app_error'}
this does not work

this will show up in debug console as an assigned template variable but you will not be able to access it inside the template.. this is what ive found.. anyways

{validate..... assign='app_error'}
{$app_error}
this works

just an FYI

thanks

jeff
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jun 29, 2004 10:01 pm    Post subject: Reply with quote

That is right, the $app_error variable is appended to as the template gets rendered. That is because the tags themselves print the error message in the case you are not assigning or appending. So to make this work, put your validate tags at the very top before $app_error is used.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jun 29, 2004 10:09 pm    Post subject: Reply with quote

Hmm, I suppose it would be possible to do the assigning/appending during the is_valid() function call. That way the assigned/appended template variables would already be populated before the template is drawn (since the messages are known.) Then in the template, the validators that had assign/append would just be silent.

The only "problem" I see is if you (as a developer) changed the error message after the form was registered and drawn once. It might be confusing to not see the changes right away until you figure out that the message was saved in the session and must be reset first. Maybe that isn't such a big deal though.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jun 29, 2004 10:43 pm    Post subject: Reply with quote

I updated CVS so the smarty vars are assigned during the is_valid function call. Now you can use your assigned/appended vars from anywhere in the templates, even before the {validate ...} tags.

Let me know if anything doesn't work right.
Back to top
View user's profile Send private message Visit poster's website
pabianjs
Smarty Rookie


Joined: 28 Jun 2004
Posts: 6

PostPosted: Wed Jun 30, 2004 7:41 pm    Post subject: Reply with quote

i will check out the new code shortly and perform some tests.

im kinda on the fence regarding the issue of when a person could use the appended variable.. i was stumped at first as to why it wasnt showing up which led me to do some testing.

either way it will work, maybe a comment in the docs giving a warning about the poetential change not showing up unless using the reset function when using the appended var ahead of the validation tags.

thanks and i will let you know
Back to top
View user's profile Send private message
delynnb
Smarty n00b


Joined: 10 Oct 2004
Posts: 1

PostPosted: Sun Oct 10, 2004 4:09 pm    Post subject: RE: does the append function attribute work Reply with quote

mohrt wrote:
I updated CVS so the smarty vars are assigned during the is_valid function call. Now you can use your assigned/appended vars from anywhere in the templates, even before the {validate ...} tags.

Let me know if anything doesn't work right.


Thanks for this wonderful plugin. It really makes form validation a ton easier!

I've ran into a small problem using this new feature though and wondered if I might not make a suggestion as to how the "append" feature works. While using the following code:

{validate field="first_name" criteria="notEmpty" transform="trim" message="First Name cannot be empty." append="errors"}
{validate field="last_name" criteria="notEmpty" transform="trim" message="Last Name cannot be empty." append="errors"}
{section name=i loop=$errors}
<li class="error">{$errors[i]}</li>
{/section}

I found that the errors variable would not display as expected in the section loop. The section would loop the correct number of times, but would never print the actual message(s).

I decided to start looking at the code, and I noticed that you are assigning the messages to an associative array that has it's keys being the form field name. This sounded logical and useful, but I wondered if not having index values was causing the section statement to freak out. I altered the code, this fixed my problem.

My question is, am I doing something wrong in the section statement that is keeping it from displaying the messages, or is my code change necessary to accomplish what I am wanting to do?

Thanks for this wonderful plugin and I anxiously await your comment on this matter.

--
DeLynn
Back to top
View user's profile Send private message
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 -> Add-ons 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