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 ... 13, 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
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Fri Oct 22, 2004 7:54 pm    Post subject: Reply with quote

what about doing this in the Template?

Code:

{ validate }
<form> {* no name, except there are several forms!*}
   <message value="There were errors on your form!" />
   <field name="username">
       <tag name="username_is_empty">
          <criteria name="isNotEmpty" />
          <transform name="trim" />
          <message value="Username cannot be empty!" />
       </tag>
   </field>
   <field name="password">
       <tag name="password_is_empty">
          <criteria name="isNotEmpty" />
          <transform name="trim" />
          <message value="Password cannot be empty!" />
       </tag>
       <tag name="password_not_match">
          <criteria name="isEqual" field2="password2" />
          <message value="Passwords do not match!" />
       </tag>
   </field>
</form>
{ validate }


<input type='text' name='username'/>
<input type='text' name='password'/>
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 22, 2004 8:00 pm    Post subject: Reply with quote

What are you gaining, besides a lot of complexity?
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: Sat Oct 23, 2004 12:36 am    Post subject: Reply with quote

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


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

PostPosted: Sat Oct 23, 2004 3:36 am    Post subject: Reply with quote

in the template?
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: Sat Oct 23, 2004 4:00 am    Post subject: Reply with quote

It looks similar to the idea of XForms where the look-and-feel is distinguished from the actions to be taken. In XForms, the action description is in the head of the document while the display description is in the body. I see the idea being that the declaration of properties and relationships is a different thing than the declaration of the presentation itself. I'm not sure how keen I am on XForms, but there is precedence for this type of separation.

I don't suppose that SmartyValidate is after the same target that XForms aims for, so the extra abstraction may not be warranted. Still, I think it makes a fair discussion point.
Back to top
View user's profile Send private message
DonJ
Smarty n00b


Joined: 12 Nov 2004
Posts: 1

PostPosted: Fri Nov 12, 2004 1:11 am    Post subject: Reply with quote

I have a couple of problems getting this to work.
My template looks like this:
[php:1:c1eca8a458]
<form action="{$form_url}" method="post">
<p>
{foreach from=$errormsgs item=errormsg}{strip}
{$errormsg}<br>
{/strip}{/foreach}

{validate field="newpw" criteria="isEqual" field2="newpw2" message="Passwords do not match" append="errormsgs" halt="yes"}
{validate field="newpw2" criteria="isRange" low="3" high="5" message="Password must be in range" append="errormsgs"}
{validate field="newpw2" criteria="isRegExp" expression="/^([a-zA-Z0-9])*$/" message="Password must not contain any special chars and whitespaces"}
</p><p>

New Password: <INPUT TYPE="PASSWORD" name="newpw"><br>
Repeat new password: <INPUT TYPE="PASSWORD" name="newpw2"><br>
<INPUT TYPE="SUBMIT" value="Change password">
</from>

[/php:1:c1eca8a458]

And the form points to this php code:

[php:1:c1eca8a458]<?php
session_start();
ob_start();
header("Cache-control: private");
...
class ..
//form validation
if(!SmartyValidate::is_valid($_POST)) {

$this->view($acct);
return false;
}
SmartyValidate::disconnect();
$this->save();
..
?>[/php:1:c1eca8a458]

I get all the time the erorr: Password must be in range (although it is in range)
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri Nov 12, 2004 3:54 pm    Post subject: Reply with quote

use isLength instead of isRange.
Back to top
View user's profile Send private message Visit poster's website
AcidMaX
Smarty Rookie


Joined: 26 Nov 2003
Posts: 16

PostPosted: Wed Nov 17, 2004 10:04 pm    Post subject: Reply with quote

It appears SmartyValidate does not want to validate when the field name is something like

test[test_field]

{validate field="test[test_field]" criteria="notEmpty" message="* REQUIRED *"}
<input type="text" name="test[test_field]" value="{$test.test_field}">

My code and everything works fine if I just make the field something like test_field, but with test[test_field] it doesnt seem to work. Maybe its not recognizing the field name as an array, like POST does? I tried field =test.test_field as well in the validate tag. Any ideas?

Thanks,
Andy
Back to top
View user's profile Send private message
AcidMaX
Smarty Rookie


Joined: 26 Nov 2003
Posts: 16

PostPosted: Wed Nov 17, 2004 10:07 pm    Post subject: Reply with quote

Nevermind I found the following thread: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=3587

Doesn't do nested arrays yet.
Back to top
View user's profile Send private message
Timm
Smarty n00b


Joined: 21 Nov 2004
Posts: 2

PostPosted: Sun Nov 21, 2004 3:28 pm    Post subject: Reply with quote

I think I've discovered a bug.

You've something like that in your code (SmartyValidate.class.php, line 152):
Code:

if($_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field], $_sess[$_key], $formvars, $form))
                      $formvars[$_field] = $_new_val;


The problem here is the if-statement.
I had a textfield which should get trimmed. For example, somebody entered " " (without the quotes). Then this string gets trimmed, and the result is an empty string (length: 0)
Then this looks something like that:
Code:

if( "" )
{

}


But the if-statement will evaluate to false, meaning the following block will not be executed. This will cause the string to stay untrimmed.

By the way: What's the if-statement for?

Hope it helps. Wink
Back to top
View user's profile Send private message
Daisuke Sano
Smarty n00b


Joined: 20 Dec 2004
Posts: 2

PostPosted: Mon Dec 20, 2004 6:36 am    Post subject: Reply with quote

I've met the same problem about the 'trim' transformer.
I hope you resolve this problem any way.

For example, the following patch is useful?
Any problem?

Code:
*** libs/SmartyValidate.class.php   2004-07-13 23:48:08.000000000 +0900
--- /home/ymmt/ogre_code/code/smarty/libs/SmartyValidate.class.php   2004-12-20 14:13:20.000000000 +0900
***************
*** 149,156 ****
                                  $formvars[$_field][$_x] = $_new_val;
                          }
                      } else {
!                          if($_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field], $_sess[$_key], $formvars, $form))
!                              $formvars[$_field] = $_new_val;
                      }
                  }
              }
--- 149,157 ----
                                  $formvars[$_field][$_x] = $_new_val;
                          }
                      } else {
!                         $_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field], $_sess[$_key], $formvars, $form);
!                         if($_new_val !== false)
!                             $formvars[$_field] = $_new_val;
                      }
                  }
              }

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 20, 2004 2:52 pm    Post subject: Reply with quote

That is a bug, it was being tested correctly in the if statement above it, but not the else. The fix is committed to CVS.
Back to top
View user's profile Send private message Visit poster's website
Daisuke Sano
Smarty n00b


Joined: 20 Dec 2004
Posts: 2

PostPosted: Wed Dec 22, 2004 12:16 am    Post subject: Reply with quote

Thank you so much!
Back to top
View user's profile Send private message
jflaflamme
Smarty n00b


Joined: 29 Jun 2005
Posts: 1

PostPosted: Wed Jun 29, 2005 6:08 pm    Post subject: Reply with quote

Hi,

I've read doc, searched forums, tried multiple combinations file[] or file etc ..

I try to validate a file array.

I have field like this <input name="fichiers[]" type="file" id="fichiers[]" ...

my validation is :
{validate page = "1" id = "v_fichiers" message = "whatever"}

in PHP
SmartyValidate::register_validator('v_fichiers', 'fichiers:10k','isFileSize', false, false);


The only explaination i see is, SmartyValidate doesn't support $_FILES arrays ...

Am i right ?

Thanks in advance and keep up your good work !
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed Jun 29, 2005 8:08 pm    Post subject: Reply with quote

You would have to choose a particular element such as fichiers[0], or write a custom validator that traverses your array.
Back to top
View user's profile Send private message 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 -> Add-ons All times are GMT
Goto page Previous  1, 2, 3 ... 13, 14, 15, 16, 17, 18  Next
Page 14 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