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: a simple yet powerful form validation plugin
Goto page Previous  1, 2, 3 ... 14, 15, 16, 17, 18  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
crash0very2k
Smarty n00b


Joined: 11 Jul 2005
Posts: 1

PostPosted: Mon Jul 11, 2005 3:51 am    Post subject: Validator w/ javascript first? Reply with quote

Can SmartyValidate validate on the client w/ javascript before post the form to webserver? Sorry if duplicate, i cant find the post about this problem
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Jul 11, 2005 1:21 pm    Post subject: Re: Validator w/ javascript first? Reply with quote

crash0very2k wrote:
Can SmartyValidate validate on the client w/ javascript before post the form to webserver? Sorry if duplicate, i cant find the post about this problem


SmartyValidate has no javascript features.
Back to top
View user's profile Send private message Visit poster's website
zoki_
Smarty n00b


Joined: 14 Jul 2005
Posts: 3

PostPosted: Thu Jul 14, 2005 7:41 pm    Post subject: Reply with quote

hi

In my php code (on the page where I use SmartyValidate), in certain cases I have to use die() command. So if the execution 'dies' and user hits back button in browser, next time he submits the same form, it will display errors... One of them is:

Quote:

Warning: Smarty error: validate: validator id 'name' is not registered. in e:\web\kalendar\libs\Smarty.class.php on line 1088


It works OK if the execution doesn't 'die'.

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


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

PostPosted: Thu Jul 14, 2005 9:01 pm    Post subject: Reply with quote

Post an example of your code. It is likely that the validator is not getting registered like it should, then the second time around it tries to validate an unregistered validator.

As for programming practice, using die() to abruptly terminate code execution is generally going to create more error/debug/maintenance problems for you down the road, not just with SmartyValidate.
Back to top
View user's profile Send private message Visit poster's website
rhododendronbusch
Smarty Rookie


Joined: 17 Mar 2005
Posts: 9
Location: Germany

PostPosted: Fri Aug 26, 2005 3:16 pm    Post subject: End-Validation-Tag Reply with quote

Hello.

I'm developing a small application with a lot of forms. I started to use SmartyValidate. I read the complete thread about this plugin (or addon) and on page 12 somebody suggested to encapsulate the errormessage by an ending validate tag like
Code:
{/validate}

Was this suggestion declined? If so I didn't get why!? IMHO this is a good suggestion.

Perhaps both methods at the same time are possible:
    Method I:
    Code:
    {validate id="sv_test" message="Errortext"}

    Method II:
    Code:
    {validate id="sv_test"}Errortext{/validate}


Regards, rhododendronbusch
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri Aug 26, 2005 4:54 pm    Post subject: Reply with quote

nope, {validate} is not a block function.
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri Aug 26, 2005 11:38 pm    Post subject: Reply with quote

I think it would be trivial to add a {validate_block} function, but there is a simple workaround when you want more complicated text:

Code:
{capture assign=foo}
bar
{/capture}
{validate id="sv_test" message=$foo|escape}
Back to top
View user's profile Send private message
rhododendronbusch
Smarty Rookie


Joined: 17 Mar 2005
Posts: 9
Location: Germany

PostPosted: Mon Aug 29, 2005 10:57 am    Post subject: Reply with quote

mohrt wrote:
nope, {validate} is not a block function.

not or not yet?
I just wanted to act on the suggestion that was made some time before!

@boots: Nice workaround! Wink
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Aug 29, 2005 1:59 pm    Post subject: Reply with quote

There is currently no plan to implement the block function. You could also put your error messages in config files:

Code:
{config_load file="err.conf"}
{validate ... message=#errmsg#}


err.conf:

Code:
errmsg = """
There was an error.
Please enter your name again.
"""
Back to top
View user's profile Send private message Visit poster's website
rhododendronbusch
Smarty Rookie


Joined: 17 Mar 2005
Posts: 9
Location: Germany

PostPosted: Tue Aug 30, 2005 12:05 pm    Post subject: Reply with quote

What a bummer!

Anyway the workaround from boots fits to my needs...

Thx for the help!
Back to top
View user's profile Send private message
andrea_c75
Smarty n00b


Joined: 11 Dec 2005
Posts: 2

PostPosted: Sun Dec 18, 2005 4:05 pm    Post subject: Bug found? Reply with quote

Problem
---------
If you use the following:

SmartyValidate::register_validator('v_id','id[0]','notEmpty');

The array value will not be validate correctly. The problem is in the SmartValidate class around line 244 (and around line 203):

if($_field_key)

$_field_key is the index of the array. In this case it's 0 and the condition is false but it should be true (I actually set an index).

Solution
---------

Change

if($_field_key)

into

if(isset($_field_key))

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


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

PostPosted: Mon Dec 19, 2005 4:34 pm    Post subject: Reply with quote

fixed in CVS, thanks!
Back to top
View user's profile Send private message Visit poster's website
Canthlian
Smarty n00b


Joined: 30 Dec 2005
Posts: 1

PostPosted: Fri Dec 30, 2005 9:06 pm    Post subject: Multiple seperate forms? Reply with quote

Okay, maybe I'm missing something horribly obvious, but the documentation is very sketchy on this point, so...

On my page, I have multiple, seperate forms. Neither one will ever interact with the other. Specifically, I have a form to login to a system, and a form to request a new password. Now, the code I'm using to register these forms with SmartyValidate is this:

SmartyValidate::connect($smarty);
if(!SmartyValidate::is_registered_form('login_user')) {
SmartyValidate::register_form('login_user');
SmartyValidate::register_validator('login_username_okay', 'login_username',
'notEmpty', false, false, 'trim', 'login_user');
SmartyValidate::register_validator('password_okay', 'password:6:-1',
'isLength', false, false, 'trim', 'login_user');
}
if(!SmartyValidate::is_registered_form('reset_password')) {
SmartyValidate::register_form('reset_password');
SmartyValidate::register_validator('reset_username_okay', 'reset_username',
'notEmpty', false, false, 'trim', 'reset_password');
SmartyValidate::register_validator('email_okay', 'email', 'isEmail', false,
false, 'trim', 'reset_password');
}

And the code I'm using to check the form is a switch to decide which form has been submitted, and an If statement to check if the form passed validation.

switch($_POST['submit_type']) {
case 'login_user':
if(SmartyValidate::is_valid($_POST, 'login_user')) {
#do code here...
}

and so on, and so on. Unfortunately, I can't seem to get either form to validate. So, is there something I'm missing, or am I just doing this wrong?


EDIT: After a lot of playing around, I finally managed to work it out. For the record, the documentation, while accurate, could really use an update. Or at least a tutorial, to explain certain concepts of the plugin.
Back to top
View user's profile Send private message
Milkman
Smarty Regular


Joined: 21 Nov 2005
Posts: 57
Location: Loughborough, UK

PostPosted: Sun Jan 22, 2006 3:49 am    Post subject: Reply with quote

Wow, okay so I've just spent the past hour reading this thread! Shocked And I should probably get some sleep at some point but I thought I'd throw a little in, just incase you decide to do any more updating...

Something I've noticed whilst working with some of the PEAR packages is their extensive use of arrays. Perhaps a suitable configuration method would be a php array. Easy for php to parse and quite easy to structure, something like the following might work, something inside <> should be replaced with a value.
[php:1:5debeeb7b1]$valid_conf = array(
'<form>' => array(
'<id>' => array(
'field' => '<field>',
'criteria' => '<criteria>',
'emtpy' => <empty>,
'halt' => <halt>,
'transform' => array('<transform>')
),
),
);[/php:1:5debeeb7b1]
It would be easy with this to extend the <id> array to include a params[] that need to be passed to the criteria function;

To take the example from index.php:
[php:1:5debeeb7b1]$valid_conf = array(
'default' => array(
'fname' => array(
'field' => 'FullName',
'criteria' => 'notEmpty'
),
'fdate' => array(
'field' => 'Date',
'criteria' => 'isDate'
)
)
);[/php:1:5debeeb7b1]
The only other thing I'm not 100% convinced about at the moment is the storage of the validation data in the session. I agree with remembering what's been validated but is it necessary to keep a copy of the validation spec in each session? The array method would be easy to set the config at the top of a file and include it when initializing the class.
Back to top
View user's profile Send private message Visit poster's website
NoWhereMan
Smarty Rookie


Joined: 14 Feb 2006
Posts: 15

PostPosted: Tue Feb 14, 2006 7:26 am    Post subject: Reply with quote

Sure I'm lazy Very Happy
A little suggestion (take it for what is worth)
This is great, but it would be even greater if the registerform and registervalidator stuff could be done from the template itself (you could pass through sessions the properties)

Code:

{validate id="fname" connect="FullName" message="Full Name cannot be empty" criteria="login_username"}
    Full Name: <input type="text" name="FullName">


EDIT: I see now this was in part implemented, and now deprecated
EDIT2: Using append I see it's actually appending in myvar[n] (where n is a progression number) and in myvar[field] (wehre field is the name of the field) is this behaviour correct?
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 ... 14, 15, 16, 17, 18  Next
Page 15 of 18

 
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