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

SmartyValidate 2.7 released
Goto page Previous  1, 2, 3, 4  Next
 
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
eddie
Smarty n00b


Joined: 10 Jul 2006
Posts: 4

PostPosted: Mon Jul 10, 2006 3:06 am    Post subject: Reply with quote

Hey!

I'm trying this plugin out, and so far it looks great! The documentation's a bit rough to read since it's all plain text, but other than that, it looks good so far.

That said, I'm finding that it doesn't seem to be possible to have a context-sensitive "mark" for when there's an error, followed up by a "summary" at the bottom of errors.

i.e.:

Username: [text-box]
Email: [text-box]
[Submit]

User doesn't put anything in, clicks "Submit", I'd like to see something like this:

Username: [text-box] *
Email: [text-box] *
[Submit]

Errors were detected:

* - Please enter your username!
* - Please enter your email!

Please correct these errors and try again.

What I'm finding, is that if I reuse the same validator ID, I get the last error message, so I can't have something like this:

Code:

<td>Username</td>
<td>
  <input type="text" name="username">
  {validate form="Register" id="UsernameValidator" message="*"}
</td>

{* ... snip ... *}

Errors:

{validate form="Register" id="UsernameValidator" message="* - Your username is incorrect!"}



Instead, it ends up showing up with the "* - Your username is incorrect" for both the first *and* the second {validate} call.

Is there a way to achieve what I want? I can't even seem to do it from the PHP side, since there doesn't seem to be a way to find out *which* validators failed (i.e., so I could append to a {$RegisterErrors} array, or something).

Maybe I'm doing this wrong -- any help would be appreciated!
_________________
Kicking Dragon (dot) com - Technical Ramblings of a Game Programmer
Back to top
View user's profile Send private message
eddie
Smarty n00b


Joined: 10 Jul 2006
Posts: 4

PostPosted: Mon Jul 10, 2006 7:30 am    Post subject: Reply with quote

Hrmm, I've "solved" my issue by creating two validators, and that seems to work well enough.

My only 'other' issue is that it doesn't seem possible to set the 'message' from PHP, but it does seem possible to do so from template-land.

I would want to set it from PHP, since that's where I'm specifying my criteria, which means that my message is less likely to fall out of sync with the criteria being specified.

My one local fix so far has been to augment register_validator with an additional parameter ($message=""), and to modify the function.validate.php's init call to only set the '$message' from the {validate} call if it's got data, otherwise to leave it alone.

Is there a better way of doing what I'm doing? If not, could these changes be added? Smile

Please let me know!
_________________
Kicking Dragon (dot) com - Technical Ramblings of a Game Programmer
Back to top
View user's profile Send private message
arne_anka
Smarty Rookie


Joined: 26 Jun 2006
Posts: 6

PostPosted: Mon Jul 17, 2006 8:55 am    Post subject: Reply with quote

seems, the validator ignores setting fields to "may be empty", i e
Code:

SmartyValidate::register_validator('phone', 'Phone', 'isNumber', true,  false, 'trim');

if i try the example given, the form is not send until _all_ fields are filled in, which is clearly against the given parameters allowing "Phone" and "Date" to be empty!
i still do not find the bug in the code (either in the example in the documentation or in SmartyValidate itself).
any help is highly appreciated ...
Back to top
View user's profile Send private message
LeGaS
Smarty Rookie


Joined: 14 May 2005
Posts: 17
Location: Hungary

PostPosted: Wed Jul 19, 2006 3:54 pm    Post subject: Reply with quote

I get this error, when try to validate a form:
Quote:
Notice: SmartyValidate: [validate plugin] form 'default' is not registered.

How can I fix it?
Back to top
View user's profile Send private message
arne_anka
Smarty Rookie


Joined: 26 Jun 2006
Posts: 6

PostPosted: Wed Jul 19, 2006 6:21 pm    Post subject: Reply with quote

LeGaS wrote:
I get this error, when try to validate a form:
Quote:
Notice: SmartyValidate: [validate plugin] form 'default' is not registered.

How can I fix it?


according to my limited experience it means usually, that you need to do
Code:

SmartyValidate::connect(&$yourSmartyInstance)

-- or you need to register your form with
Code:

SmartyValidate::register_form('yourForm')
Back to top
View user's profile Send private message
LeGaS
Smarty Rookie


Joined: 14 May 2005
Posts: 17
Location: Hungary

PostPosted: Thu Jul 20, 2006 7:02 am    Post subject: Reply with quote

Thanks for your help, but I solved it in an other way. Smile It isn't possible to validate in a switch. ^^ Now I included the form and the validating, and it works!
Back to top
View user's profile Send private message
dotmx
Smarty n00b


Joined: 04 Aug 2006
Posts: 1

PostPosted: Fri Aug 04, 2006 5:17 pm    Post subject: Reply with quote

i have the following problem when trying to run the example included in smartyValidate's docs:

PHP Fatal error: Smarty error: [in form.tpl line 3]: syntax error: unrecognized tag 'validate' (Smarty_Compiler.class.php, line 583)

that line contains the first {validate} tag.


what seems to be the problem?

im on the latest smarty and smartyValidate release running on php5 on a mac.
Back to top
View user's profile Send private message
arne_anka
Smarty Rookie


Joined: 26 Jun 2006
Posts: 6

PostPosted: Sat Aug 05, 2006 5:25 pm    Post subject: Reply with quote

dotmx wrote:
i have the following problem when trying to run the example included in smartyValidate's docs:

PHP Fatal error: Smarty error: [in form.tpl line 3]: syntax error: unrecognized tag 'validate' (Smarty_Compiler.class.php, line 583)

that line contains the first {validate} tag.


what seems to be the problem?

im on the latest smarty and smartyValidate release running on php5 on a mac.


you probably either did not install SmartyValidate correctly or you forgot to include SmartyValidate.class.php (check whether the path matches)
Back to top
View user's profile Send private message
Snover
Smarty n00b


Joined: 16 Aug 2006
Posts: 2

PostPosted: Wed Aug 16, 2006 7:35 pm    Post subject: SmartyValidator not ignoring multiple validator fails Reply with quote

Hello,

I am using SmartyValidator and am using the validate 'append' to put the messages to an array which I read out later. This is working fine. I have multiple validators on a single form element. This is not working so fine. According to the README,

Quote:
Multiple validators may be used for one field. Once one validator fails, the remaining validators for that field are ignored. A "halt" parameter can also stop validation on remaining fields.


However, the 'ignore remaining validators' thing is not happening. On empty fields, ALL of the validators are firing failure messages. Furthermore, my attempt to suppress these errors by setting $empty = true has failed, even though I have the correct code in place for this in my custom validators.

[php:1:eb9d8c4957]SmartyValidate::register_validator('username', 'username', 'isAlNum', false, false, 'trim');
SmartyValidate::register_validator('fresh_username', 'username', 'isAvailableUsername', false, false, 'trim');
SmartyValidate::register_validator('reserved_username_words', 'username', 'hasBadWords', false, false, 'trim');[/php:1:eb9d8c4957]

validate_criteria.isAlNum.php:
[php:1:eb9d8c4957]<?
/**
* Test if value contains only alpha-numeric characters
*
* @param string $value the value being tested
* @param boolean $empty if field can be empty
* @param array params validate parameter values
* @param array formvars form var values
*/

function smarty_validate_criteria_isAlNum($value, $empty, &$params, &$formvars)
{
if(strlen($value) == 0)
{
return $empty;
}

return !preg_match('/[^A-Za-z0-9]/', $value);
};
?>[/php:1:eb9d8c4957]

(I won't spam this thread with the other validators, but they are very similar.)

I'm pretty sure it's a bug, but I've done made more than my fair share of bogus reports in the past, so it would be great if someone could verify this and/or find a fix.

(P.S. I have been awake for 22 hours, so please excuse this message if it is highly inappropriate. DX)
Back to top
View user's profile Send private message
NoWhereMan
Smarty Rookie


Joined: 14 Feb 2006
Posts: 15

PostPosted: Wed Aug 30, 2006 11:26 am    Post subject: Reply with quote

is there a way to add a validator using php code? I mean, not registering, but having the same behaviour of the {validator} tag

thanx
Back to top
View user's profile Send private message
oZZ
Smarty n00b


Joined: 15 Mar 2006
Posts: 3

PostPosted: Sat Sep 09, 2006 4:45 pm    Post subject: Reply with quote

Hi,

I made an inArray-Validator. It simply tests if a Value is in an Array like in_array(). Perhaps someone's interested in it or has got an idea how to improve ist.

Code:

function smarty_validate_criteria_inArray($value, $empty, &$params, &$formvars) {
    if(strlen($value) == 0)
        return $empty;
    return in_array($value, array_slice($params, 1, count($params)-9));
}

SmartyValidate::register_validator('v_value', 'value:'.implode(':', $array), 'inArray', false, false, 'trim' );


Back to top
View user's profile Send private message
charlie
Smarty n00b


Joined: 06 Oct 2006
Posts: 4

PostPosted: Fri Oct 06, 2006 11:39 am    Post subject: Multiple validators error messages Reply with quote

He Snover,

I experienced the same thing when using multiple validators on a single form value:
Code:
SmartyValidate::register_validator('first_name', 'vfirst_name', 'notEmpty',  false, false, 'trim');
  SmartyValidate::register_validator('first_name_alnum', 'vfirst_name:/[0-9a-z\.]+/i', 'isRegExp');

Template:
Code:
{validate id="first_name" message="$ErrNotEmpty"}{validate id="first_name_alnum" message="$ErrNotAlnum"}


But when the form value of first_name is empty I see both error messages in my page.

I must ise the 'halt' but I don't want that.
Somebody a fix or solution?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri Oct 06, 2006 2:05 pm    Post subject: Reply with quote

You must use halt (fifth param "true") to stop the validation:

Code:
SmartyValidate::register_validator('first_name', 'vfirst_name', 'notEmpty',  false, true, 'trim');
SmartyValidate::register_validator('first_name_alnum', 'vfirst_name:/[0-9a-z\.]+/i', 'isRegExp');
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: Fri Oct 06, 2006 2:07 pm    Post subject: Re: SmartyValidator not ignoring multiple validator fails Reply with quote

Snover wrote:
Hello,

I am using SmartyValidator and am using the validate 'append' to put the messages to an array which I read out later. This is working fine. I have multiple validators on a single form element. This is not working so fine. According to the README,

Quote:
Multiple validators may be used for one field. Once one validator fails, the remaining validators for that field are ignored. A "halt" parameter can also stop validation on remaining fields.


However, the 'ignore remaining validators' thing is not happening. On empty fields, ALL of the validators are firing failure messages.


You must set the "halt" attribute to true (fifth param of register_validator()) to halt validation on any one validator if it fails.
Back to top
View user's profile Send private message Visit poster's website
charlie
Smarty n00b


Joined: 06 Oct 2006
Posts: 4

PostPosted: Sun Oct 15, 2006 6:35 pm    Post subject: Reply with quote

Hi,

I use Validate for multiple forms in one page. It works because use of the 'form' id. But now in all my forms the error mesasges in the template doesn't work anymore.

This is a snippet of my code:
Code:
 SmartyValidate::register_validator('email', 'vemail', 'isEmail', false, false, 'trim', 'vcard');

Template:
Code:
<input type="text" name="vemail" size="30" value="{$vemail|escape}" /> <span class="error">{validate id="email" message="$ErrWrongEmail" form="vcard"}</span>


Anyone any idea?
_________________
Freelance PHP programmer
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
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
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