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 ... 9, 10, 11 ... 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
mohrt
Administrator


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

PostPosted: Wed Jun 30, 2004 2:01 pm    Post subject: Reply with quote

That is getting confusing, but there may be a way to handle this. One idea:

Code:
{validate field="field1,field2" criteria="notEmpty" ... }


If there is more than one field listed in the "field" section, the validator is OR'ed against those fields. (If you want AND, you use separate validators for each field as usual.)

I'm not sure if that is any clearer though, at first glance the validator looks as if all the fields must pass the validation.

Another idea:

Code:
{validate field="field1,field2,field3" criteria="notEmpty" ... }
{validate field="field1|field2|field3" criteria="notEmpty" ... }


Here the first one AND's the fields, the second one OR's the fields. This at least adds a little flexability. I'm still not sure I like introducing a new separator though. Also, I don't think AND'ing would be terribly useful, you would normally want separate error messages for each field. I suppose "field1&field2&field3" is yet another option, but then what's the difference between commas and "&".

So the big question is, introducing new separators or not. Sticking with commas keeps the syntax to a minimum, but new separators may keep the statements shorter or easier to understand.
Back to top
View user's profile Send private message Visit poster's website
hristov
Smarty Rookie


Joined: 04 Jun 2004
Posts: 24

PostPosted: Thu Jul 01, 2004 2:26 am    Post subject: Reply with quote

Another idea:
Code:

{validate_group criteria="OR" message="something is wrong"}
  {validate filed="filed1" criteria="notEmpty"}
  {validate field="field2" criteria="notEmpty"}
{/validate_group}

mohrt wrote:

Another idea:

Code:
{validate field="field1,field2,field3" criteria="notEmpty" ... }
{validate field="field1|field2|field3" criteria="notEmpty" ... }


________
Chevrolet luv


Last edited by hristov on Sat Feb 12, 2011 7:44 pm; edited 1 time in total
Back to top
View user's profile Send private message
DJSmooth
Smarty Rookie


Joined: 26 Jun 2004
Posts: 10

PostPosted: Thu Jul 15, 2004 10:52 am    Post subject: short tip Reply with quote

i don't know if this was discussed already...

Code:
// required initialization
    SmartyValidate::connect($smarty);
   
    if(empty($_POST)) {

       $query = "SELECT * FROM users WHERE id='$id'";
       $query = mysql_query($query);
       $row = mysql_fetch_array($query);

       $smarty->assign('data', $row);

       $smarty->display('form.tpl');
    } else {   
       // validate after a POST
       if(SmartyValidate::is_valid($_POST)) {
           // no errors, done with SmartyValidate
           SmartyValidate::disconnect();

"MAYBE A SQL DB UPDATE"

           $smarty->display('success.tpl');

       } else {
           // error, redraw the form
           $smarty->assign('data',$_POST); //<-- The edited form fields stay edited
           $smarty->display('form.tpl');
       }



sorry for my sad english.
it is just a modification for people that want to have the edited fields stay edited.
maybe someone will say that everyone knows that...but anyway.

btw: thanks for this great add-on
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 15, 2004 1:46 pm    Post subject: Reply with quote

The examples do assign the $_POST data back, or are you talking about something else?
Back to top
View user's profile Send private message Visit poster's website
DJSmooth
Smarty Rookie


Joined: 26 Jun 2004
Posts: 10

PostPosted: Thu Jul 15, 2004 2:48 pm    Post subject: Reply with quote

yes they do... you have to do:

Code:
<input type="text" name="FullName" value="{$FullName|escape}"><br />


in this:

Code:

<input type="text" name="FullName" value="{$data.FullName}"><br />
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 15, 2004 3:15 pm    Post subject: Reply with quote

Yes, the template variable you use is determined by how the $_POST data is assigned. I guess I missed the question/concern here.
Back to top
View user's profile Send private message Visit poster's website
pt2002
Smarty Regular


Joined: 05 May 2003
Posts: 89
Location: Porto, Portugal

PostPosted: Fri Jul 16, 2004 9:39 am    Post subject: Reply with quote

One vote for this one

{validate field="field1,field2,field3" criteria="notEmpty" ... }
{validate field="field1|field2|field3" criteria="notEmpty" ... }

or

{validate field="field1,field2,field3" criteria="notEmpty" ... }
{validate field="field1.field2.field3" criteria="notEmpty" ... }

Greetings
Back to top
View user's profile Send private message
hristov
Smarty Rookie


Joined: 04 Jun 2004
Posts: 24

PostPosted: Tue Jul 20, 2004 6:08 pm    Post subject: Reply with quote

I would vote for this one. It really easy to read, use and understand.
Code:

{validate_group criteria="OR" message="something is wrong"}
  {validate filed="filed1" criteria="notEmpty"}
  {validate field="field2" criteria="notEmpty"}
{/validate_group}

________
JUSTIN BIEBER


Last edited by hristov on Sat Feb 12, 2011 7:45 pm; edited 1 time in total
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Jul 20, 2004 6:57 pm    Post subject: Reply with quote

I'm thinking about replumbing the SmartyValidate framework. Ideally, the criteria should be established at registration time on the PHP side, not in the template. In the template, the logic would be reduced to testing for error messages and displaying them. Then comes the question, how to implement this without adding complication.

This was one idea:

Code:

$_params = array(
                       array('name' => 'name_not_empty', 'field' => 'name', 'criteria' => 'notEmpty', transform="trim'),
                       array('name' => 'age_is_number', 'field' => 'age', 'criteria' => 'isInt', empty => 'true')
                     );
SmartyValidate::register_form('myform', $_params);


Then in the template is reduced to something like:

Code:

{validate name="name_not_empty" message="Name cannot be empty"}
{validate name="age_is_number" message="Age must be a number"}


Or even more flexible:

Code:

{validate name="name_not_empty"}Name cannot be empty{/validate}
{validate name="age_is_number"}Age must be a number{/validate}



Since passing a big associative array is a bit difficult, maybe break this down into separate functions:

Code:

SmartyValidate::register_form('myform');
SmartyValidate::add_criteria('name_not_empty',array('criteria' => 'notEmpty', 'transform' => 'trim'), 'myform');
SmartyValidate::add_criteria('age_is_number',array('criteria' => 'isInt', 'empty' => true), 'myform');



Basically you retain the benefit of validation abstraction to function calls, yet move all the processing to the PHP side. The only shortcoming is that this isn't easy enough (IMHO.) Not sure what to do quite yet, still pondering. Thoughts are welcome Wink
Back to top
View user's profile Send private message Visit poster's website
hristov
Smarty Rookie


Joined: 04 Jun 2004
Posts: 24

PostPosted: Tue Jul 20, 2004 8:07 pm    Post subject: Reply with quote

I don't care where the validations are, in the template or the php code, as long as I have the flexibility to do complex validations with minimal work. Don't forget to incorporate into your framework AND/OR/XOR/NOT and grouping. I know that 95% of people would not use OR/XOR/NOT but they sure come handy sometimes.
________
Hot penny stocks


Last edited by hristov on Sat Feb 12, 2011 7:45 pm; edited 1 time in total
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Jul 20, 2004 8:38 pm    Post subject: Reply with quote

Moving the validation criteria to the PHP side certainly opens the doors for AND/OR tests since we don't have to come up with a funky template syntax for it.
Back to top
View user's profile Send private message Visit poster's website
hristov
Smarty Rookie


Joined: 04 Jun 2004
Posts: 24

PostPosted: Tue Jul 20, 2004 8:41 pm    Post subject: Reply with quote

If you seriosly think of doing this, go ahead so I don't have to change too much code to incorporate the new framework. You have my full support for testing it.

mohrt wrote:
Moving the validation criteria to the PHP side certainly opens the doors for AND/OR tests since we don't have to come up with a funky template syntax for it.

________
Herbalaire


Last edited by hristov on Sat Feb 12, 2011 7:45 pm; edited 1 time in total
Back to top
View user's profile Send private message
pt2002
Smarty Regular


Joined: 05 May 2003
Posts: 89
Location: Porto, Portugal

PostPosted: Wed Jul 21, 2004 8:52 am    Post subject: Reply with quote

Hi

Everything you do is fine.

I just think if we could have a way to set the same error message to a group of fields would be nice.

e.g. A form with 10 fields and 5 of them should not be empty.

Instead having 5 validate tags with halt="yes" to show "All fields marked with * can't be empty" only 1 time if any field is empty, we would have just one validate tag with the 5 fields we want to validate.

Greetings
Back to top
View user's profile Send private message
pabianjs
Smarty Rookie


Joined: 28 Jun 2004
Posts: 6

PostPosted: Thu Jul 22, 2004 8:24 pm    Post subject: validation dependencies and logical operators Reply with quote

If your going to stray down that path of using operators which might roll into dependency checking i vote no.

The business logic should handle those questions.

My vote is for the developer to handle the validation and i dont mind the multiple validations or the validation syntax itself.

This gets to be a slippery slope really quick.

Just my two cents.
Back to top
View user's profile Send private message
webadept
Smarty Regular


Joined: 09 Mar 2004
Posts: 41

PostPosted: Mon Jul 26, 2004 1:14 am    Post subject: Reply with quote

mohrt wrote:
Moving the validation criteria to the PHP side certainly opens the doors for AND/OR tests since we don't have to come up with a funky template syntax for it.


Personaly I'm not much into suggesting where someone's volenteer time is spent and how. But Getting this far in the thread I find I am pressed by overrated ego to reply in this manor.

Ive been looking at this Validator with ever growing respect, and until this very last page of the thread here, was getting out my pompoms and warming my throat for the big cheer. However, in my small little world moving the validation criteria into the PHP negates( completely )the desirablitly of a Validator to begin with.

Let's face it, I can write the validation of a form in a lot less code, much less over head and, .. less time, than it takes to use the Validator... any validator. The purpose of a validator, again, in my little world, is the designer and the maintainers of the form, and the site when i'm gone. If I wrte the validations, then they are in the PHP, and as you say, I can do a heck of a lot more than what might be possible in the template areas, but .. it requires changing PHP to alter or maintain it later.

Your valdator, up t this point, ... well maybe a few points back before a number of wishlists came in, that I noticed didn't have much code with them, started pusing the limits, and taxing the posibilies of template side validation rules ... But up to that point, my designers could write, alter, change and even create whole new forms with validation, and not have to call me. Ths has been the last area that my phone still rings. Form validatiion.

But, as I said, this is your baby and your time.. .and some realy nice code and very cool creative work has been seen by you (and others) thus far.. So if you feel that 'coders' really need another way of creating a few form validation funcitions, then, far be it from me to say otherwise.

I guess what it really comes down to is, 'why are you writing this, and for who?"

As the post suggestsed before mine.. just my two cents and . thanks for the assome effort so far.

webadept
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 ... 9, 10, 11 ... 16, 17, 18  Next
Page 10 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