View previous topic :: View next topic |
Author |
Message |
xces Smarty Regular
Joined: 09 Apr 2004 Posts: 77
|
Posted: Wed May 26, 2004 10:41 pm Post subject: |
|
|
Monthe i was just editing my reply, you should re-read my reply because i added a bug.
p.s. I verified that the sollution i provided works. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed May 26, 2004 10:47 pm Post subject: |
|
|
Another option is to put the span tags right in the message content, if the error formatting isn't any more complicated than that...
Code: | {validate field="foobar" criteria="notEmpty" message='<span class="error">can't be empty</span>'}
|
|
|
Back to top |
|
xces Smarty Regular
Joined: 09 Apr 2004 Posts: 77
|
Posted: Thu May 27, 2004 6:56 am Post subject: |
|
|
Yep i had that before, but then you are going pass the idea smarty is all about, seperating code from logic imho...
Right now i have the validate tags right after the input fields, but with long fields this is kinda not done..
Normal form: (click for large)
Failed form: (click for large)
It would be even better to "gather" all error messages, and put them into 1 "section" or so which you could use to show the errors. Lets say a form has 4 fields, and 3 of them fail to validate, normally you could (a) echo the error message right there, or (b) assign the error to a variable.
My suggestion:
How would it be if you could (c) print a "section" with all returned error messages somewhere in the compiled template? E.g. at the top of the form, "Your form failed to validate due to the following reasons: ..." Combine that with a custom error template and it might be usefull. I don't have any code atm but i will see if i can whip something up without modifiying your code to much. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu May 27, 2004 1:32 pm Post subject: |
|
|
How about a new attribute "append"
{validate ... append="errors"}
Then $errors would be an array of error messages you can loop over. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu May 27, 2004 1:59 pm Post subject: Version 1.5 released |
|
|
New version released:
http://www.phpinsider.com/php/code/SmartyValidate/
ChangeLog:
* added "append" attribute as alternate to "assign"
* added fourth parameter to custom functions to access all form vars.
I also added a "CREDITS" section to the README file. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu May 27, 2004 2:49 pm Post subject: |
|
|
oops, forgot to add to ChangeLog:
* fix bug with passing form name to custom function (bug submitted from xces) |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu May 27, 2004 2:59 pm Post subject: |
|
|
xces wrote: | Yep i had that before, but then you are going pass the idea smarty is all about, seperating code from logic imho... |
Smarty is about separation of presentation from business logic, I don't see where this applies. Putting HTML tags in a variable that comes from a template shouldn't cause problems. |
|
Back to top |
|
xces Smarty Regular
Joined: 09 Apr 2004 Posts: 77
|
Posted: Fri May 28, 2004 7:03 am Post subject: |
|
|
Thanx for te update! There is a so called "Edit" button could have saved you a couple of replys |
|
Back to top |
|
electr0n Smarty Rookie
Joined: 26 Mar 2004 Posts: 32 Location: Germany
|
Posted: Fri May 28, 2004 6:00 pm Post subject: |
|
|
Is it possible to add a new param, which executes a custom function to the post variable, like trim? Remove the trim attribut and use this instead. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri May 28, 2004 6:31 pm Post subject: |
|
|
I see what you are asking. My question would be, what other form data munging would be useful, and correct to handle here?
If this were to be implemented, I can think of two ways off the top of my head:
New attribute type "execute":
{validate name="foo" execute="trim" ...}
New criteria type "execute":
{validate name="foo" criteria="execute" func="strtoupper" ...}
A couple of issues that come along with this is execution of multiple functions on one form element, and registering the called functions for security.
Good topic though... |
|
Back to top |
|
electr0n Smarty Rookie
Joined: 26 Mar 2004 Posts: 32 Location: Germany
|
Posted: Fri May 28, 2004 8:05 pm Post subject: |
|
|
mohrt wrote: |
New criteria type "execute":
{validate name="foo" criteria="execute" func="strtoupper" ...} |
Hm that's not so good I think, because therefore you've got the custom functions. I need this in the is_valid() Method, for later use. |
|
Back to top |
|
xces Smarty Regular
Joined: 09 Apr 2004 Posts: 77
|
Posted: Sat May 29, 2004 5:59 pm Post subject: |
|
|
Electron:
If you assign a custom function you can do all kind of things. E.g. i made a custom for the place where people have to change their password. Instead of using "notempty" i used "custom" which checked for empty string and after that for string with minimum length of 6 chars. The problem with an execute is also that you could require multiple params etc etc... I don't see the advantage of execute above custom...
Morthe:
I changed your code again.. I do like the append function but not the part where you say it is either this or that.. The reason for that is this... I made it possible to use both the assign and the append function. This gives me the possibility to display a custom error at the place of the error form field (like a few posts earlier) and 1 custom message like "Your form contains errors" on top of anywhere i want in the form.
Basicly to get this to work i print the error ("required field" or whatever) at where the field is in the template, and i check the count of the appended error section to see if i have to print the "Warning, your form contains errors please fix them" message.
This means i actually only use the appended error section to see if the form failed to validate (if the count > 0)... Maybe you could "assign" a new variable from within your smartyvalidate::isvalid function if the form failed to validate..
e.g. if the form failed to validate:
smarty->assign($form.'_isvalid', false);
Then in the template we could use:
{if not $default_isvalid} print custom error message {/if}
If you could add anything like that what i suggest then your code "either this or that" would be cool! |
|
Back to top |
|
electr0n Smarty Rookie
Joined: 26 Mar 2004 Posts: 32 Location: Germany
|
Posted: Sun May 30, 2004 7:42 pm Post subject: |
|
|
xces wrote: | Electron:
If you assign a custom function you can do all kind of things. E.g. i made a custom for the place where people have to change their password. Instead of using "notempty" i used "custom" which checked for empty string and after that for string with minimum length of 6 chars. The problem with an execute is also that you could require multiple params etc etc... I don't see the advantage of execute above custom... |
The criteria attribute should be used for validation and the attribute which I would like to use, should be used for transformation.
I would use this for transformation, like trim, ltrim, rtrim or for example a http upload, I would need this for my CMS, because it must be dynamic. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jun 01, 2004 3:57 pm Post subject: |
|
|
xces wrote: | This means i actually only use the appended error section to see if the form failed to validate (if the count > 0)... Maybe you could "assign" a new variable from within your smartyvalidate::isvalid function if the form failed to validate..
e.g. if the form failed to validate:
smarty->assign($form.'_isvalid', false);
|
SmartyValidate isn't tightly coupled with the Smarty object at the time is_valid() is called, so if you want a template variable for this, you'll have to assign one yourself after is_valid() fails. However, I did change the code so append and assign can be used together.
Version 1.6 is now available.
http://www.phpinsider.com/php/code/SmartyValidate/
Changes:
* change assign/append to act separately (monte, xces)
* add transform parameter, deprecate trim parameter (monte)
* add register_criteria() and register_transform() methods,
deprecate register_function() method (monte)
* add is_init() and clear() methods (monte)
Notable feature addition, you can now apply multiple transformations to a variable with the tranform attribute. example:
{validate ... transform="trim,strtolower,ucfirst"} |
|
Back to top |
|
electr0n Smarty Rookie
Joined: 26 Mar 2004 Posts: 32 Location: Germany
|
Posted: Tue Jun 01, 2004 6:23 pm Post subject: |
|
|
Great! I'll test it the next time |
|
Back to top |
|
|