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 ... 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
mohrt
Administrator


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

PostPosted: Tue Feb 14, 2006 3:13 pm    Post subject: Reply with quote

Use the latest CVS, I think some problems with append have been addressed.
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 3:58 pm    Post subject: Reply with quote

thanks, just checked it out, now i'm gonna try it Smile
Back to top
View user's profile Send private message
gawan
Smarty Rookie


Joined: 29 Apr 2003
Posts: 9

PostPosted: Tue Mar 14, 2006 10:50 am    Post subject: Validating against a group of elements Reply with quote

I would be great to be able to validate a group of form elements together, say, in style "please check at least one of the checkboxes" or "you did not provide any name information" (when there are three edit boxes for name information, and at least in one of them must not be empty).

Any suggestion on how to do this in SmartyValidate? (maybe even an idea for enhancing this plugin?)

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


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

PostPosted: Tue Mar 14, 2006 2:21 pm    Post subject: Reply with quote

You can apply multiple validators to a single form value, otherwise, you can make a custom validator do whatever you want.
Back to top
View user's profile Send private message Visit poster's website
checat
Smarty Rookie


Joined: 05 Feb 2004
Posts: 13
Location: Russia, Saint-Petersburg

PostPosted: Tue Mar 21, 2006 10:30 am    Post subject: question Reply with quote

I want to ask.
If a person opens two browser windows, can validators for that windows come into conflict? Are there any guidelines?
Back to top
View user's profile Send private message Visit poster's website
checat
Smarty Rookie


Joined: 05 Feb 2004
Posts: 13
Location: Russia, Saint-Petersburg

PostPosted: Fri Mar 24, 2006 10:00 am    Post subject: I tried and got a problem Reply with quote

Assume user opens in 2 browser windows the same form with different data Say, user wants to send 2 forum messages, but has slow connection and don't want to wait for a single window to reload. So, he opens 2 post forms, fills first form, submits. SmartyValidator gots form data, return 'ok', and script makes 'disconnect'. So, when user submits second form, validator has no clue what those data about.

I find the only possibility: never call 'diconnect'.
But I don't like such a pollution of session data.
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 Mar 24, 2006 4:00 pm    Post subject: Re: I tried and got a problem Reply with quote

checat wrote:
Assume user opens in 2 browser windows the same form with different data Say, user wants to send 2 forum messages, but has slow connection and don't want to wait for a single window to reload. So, he opens 2 post forms, fills first form, submits. SmartyValidator gots form data, return 'ok', and script makes 'disconnect'. So, when user submits second form, validator has no clue what those data about.

I find the only possibility: never call 'diconnect'.
But I don't like such a pollution of session data.


This is no different than having multiple forms on one page. Make sure you use a unique form id each time to register a form, and use that id throughout the validation process.
Back to top
View user's profile Send private message Visit poster's website
checat
Smarty Rookie


Joined: 05 Feb 2004
Posts: 13
Location: Russia, Saint-Petersburg

PostPosted: Mon Mar 27, 2006 1:39 pm    Post subject: Reply with quote

[quote] Make sure you use a unique form id each time to register a form, and use that id throughout the validation process.[/quote]

This still has some minor problems with:
1. Load Form -> Submit -> Back -> Submit
2. Load Form -> Duplicate window ("Duplicate" in Opera, "New" in IE) -> Submit first window -> Submit second Window
Both this cases has no chance to generate new form id since form is not reloaded from server.
3. Pages often contain forms that will rarely be submited by user, but their registration with unique ids fills session data with junk.

It doesn't matter. I've already made my own similar validator class/plugin which doesn't use session at all.
Back to top
View user's profile Send private message Visit poster's website
polik00
Smarty n00b


Joined: 10 Jun 2006
Posts: 3

PostPosted: Sat Jun 10, 2006 4:33 pm    Post subject: Reply with quote

Thank you so much!

Last edited by polik00 on Wed May 05, 2010 10:56 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
bensmyth
Smarty n00b


Joined: 03 Sep 2004
Posts: 4

PostPosted: Thu Sep 14, 2006 9:19 am    Post subject: Reply with quote

Is it possible to achieve the following.....

Code:
{validate id="userEmail"    append="error" message="You must provide a valid email"}
{validate id="userPassword" append="error" message="You must provide matching passwords"}

{if $error != ''}
   {foreach from=$error item="err"}
      {$err}<br/>
   {/foreach}
{/if}

{if $error.userEmail != ""}
   <div class="error">Email:</div>
{else}
   Email:
{/if}
<input name="userEmail" id="userEmail" type="text" value="{$userEmail|escape}"/>
{if $error.userEmail != ""}<div class="error">{$error.userEmail}</div>{/if}

.....


Since error stores enumerative and not assoc, this doesn't seem possible?


On a seperate not, I couldn't get {if $validate.default.is_error} to work
Back to top
View user's profile Send private message
SpiffyJr
Smarty n00b


Joined: 19 Sep 2007
Posts: 3

PostPosted: Wed Sep 19, 2007 9:28 pm    Post subject: Reply with quote

Is it possible to do something like the following:

Code:
{section name=i loop=$inputs}
<label for="{$inputs[i].ID}">{$inputs[i].LABEL}</label>
{if $inputs[i].TYPE == text}
{if $inputs[i].Validate}
{validate id="$inputs[i].ValidateID" message="$inputs[i].ValidateMessage"}
{/if}
<input type="text" name="{$inputs[i].NAME}" id="{$inputs[i].ID}">
{/if}
{/section}

I setup a form class to generate form fields and validations for me but I'm receiving this error.

Warning: Smarty error: validate: validator id 'Array.ValidateID' is not registered. in B:\web\phpRaider2\includes\class\smarty\Smarty.class.php on line 1095
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed Sep 19, 2007 9:46 pm    Post subject: Reply with quote

This is just a syntax problem, get rid of the quotes.

Code:
{validate id=$inputs[i].ValidateID message=$inputs[i].ValidateMessage}


And, don't repeat your question all over the forum!
Back to top
View user's profile Send private message Visit poster's website
SpiffyJr
Smarty n00b


Joined: 19 Sep 2007
Posts: 3

PostPosted: Thu Sep 20, 2007 2:38 am    Post subject: Reply with quote

Wasn't sure which location was best Very Happy

Thanks! I'll check it out.
Back to top
View user's profile Send private message
SpiffyJr
Smarty n00b


Joined: 19 Sep 2007
Posts: 3

PostPosted: Thu Sep 20, 2007 2:39 am    Post subject: Reply with quote

Ignore this, I made a mistake!
Back to top
View user's profile Send private message
brainwave
Smarty Rookie


Joined: 09 Jul 2003
Posts: 22

PostPosted: Tue Jan 08, 2008 4:14 pm    Post subject: Reply with quote

Hi,

first I just where happy about smarty validate, It is really helpfull and works fine for me on static sites but I have some little problems with it also Rolling Eyes

1. I don't exactly understand this SmartyValidate::register_validator thing, I expirienced that I have to call this at form generation and not after form submission. If I call connect and register_validator after form submission, right before the is_valid method it wont work. I think I have just a problem looking into the right direction Embarassed

2. Coming with this issue above, I tried to create a prototype/scriptuclous based ajax form. Its an textfield that will be replaced by a input field and sends a value via get method. Sending the value works finde it reaches the php script but I really don't know how to validate it, because smarty-validate allways says its empty (on notEmpty validation) Sad

Since the value comes to the php script the ajax stuff isn't that important so I don't waste your time with this code Smile

But here is the php code:
Code:
<?php
/*
 * Prepare Vars
 */
$_REQUEST['value'] = stripslashes($_REQUEST['value']);
$_REQUEST['value'] = str_replace('"',"'",$_REQUEST['value']);

/*
 * Main
 */
if($_REQUEST['op'] == 'save') {
   /*
    * Check Form
    */
        SmartyValidate::connect($tpl, true);
        SmartyValidate::register_validator('fvalue','value','notEmpty');

   if(SmartyValidate::is_valid($_GET)) {
      $result = $system->query("   INSERT INTO user_demand
                  (uid, value, duration, date)
                  VALUES
                  ('{$system->user['uid']}', '{$_REQUEST['value']}', '60', NOW())
                  ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id), value = VALUES(value), duration = VALUES(duration), date = VALUES(date)");

      if($result) {
         $tpl->assign('ajaxout', I_CREATED);
      } else {
         $tpl->assign('ajaxout', E_CREATED);
      }
      SmartyValidate::disconnect();
   } else { echo "<br \>invalid form!";
   }
} elseif($_REQUEST['op'] == 'edit') {
   if(!empty($_REQUEST['id'])) {
      $result = $system->query("   SELECT    id, value
                  FROM user_demand
                  WHERE id = '{$_REQUEST['id']}'");
      $data = $system->fetch($result);
      $_REQUEST['id']    = $data['id'];
      $_REQUEST['value'] = $data['value'];
      $_REQUEST['op2']   = true;
   } else {
      $tpl->assign('ajaxout', E_INVALIDID);
   }
}

/*
 * TPL
 */
$tpl->assign('content',array(   'id'   => $_REQUEST['id'],
                        'value' => $_REQUEST['value']));

//echo "<pre>"; print_r($_REQUEST); echo "</pre>";
?>


and the template:
Code:
{$content.value} {$ajaxout} {validate id="fvalue" message="##F_TEXT##"}


ah and things like session_start() where allreay beeing called by my cms system.

Hope someone could direct me into the right direction Wink

Rgds
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 ... 15, 16, 17, 18  Next
Page 16 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