Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Notice: SmartyValidate: [is_valid] method 'Validate' is not
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
newname
Smarty Rookie


Joined: 25 May 2008
Posts: 26

PostPosted: Mon May 26, 2008 2:40 pm    Post subject: Notice: SmartyValidate: [is_valid] method 'Validate' is not Reply with quote

first of all.. Thanks for the great plugin.
I didnt really need it, I had my own validation functions..
but I though it would look more professional to use Smarty Validate.. Smile
so i am using it now..
But I have many problems regarding it.
First of all, Your Forum Registeration system sucks !!!!!!
i had to register 4 times to get activation email :@
I used live[dot]com email for first try, didnt work.
then used hotmail , didnt work.
Then used mailinator[dot]com, didnt work.
then today on fourth try, i used another mailinator email, and it worked.
but I am so angry I had to use this stupid username :@
Please fix it.

And secondly, Congrats for this Awesome plugin Very Happy


now, to my point.
I was trying to register for 3 days to get this problem fixed Sad


Here is my bit of smarty code :

removed !
its a bit of my long code that doesnt work Sad
I tried both methods of validation, but no success , my template :



my form :

removed !

It gives this error upon input :



Code:
Notice: SmartyValidate: [is_valid] method 'Validate' is not valid for object 'PHPLPCaptcha'. in D:\xampp\htdocs\linkexchangesystem\smarty\SmartyValidate.class.php on line 604



Can you please please please please please help me sir??


Last edited by newname on Thu Jul 03, 2008 11:55 am; edited 1 time in total
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon May 26, 2008 4:26 pm    Post subject: Reply with quote

Does that object have a validate method?

Also be aware:
SmartyValidate::connect($smarty, true);

Wipes out the validation session, so be sure to call that only once.
Back to top
View user's profile Send private message Visit poster's website
newname
Smarty Rookie


Joined: 25 May 2008
Posts: 26

PostPosted: Mon May 26, 2008 5:01 pm    Post subject: Reply with quote

yep, only called it once.. here is the full code:

Code:
if (empty($_POST['submit'])) {
         // new form, we (re)set the session data
         SmartyValidate::disconnect();
         SmartyValidate::connect($smarty, true);
         // register criteria
         // Captcha
         if ($config['showcap'] == 'y')
         {
                                $PHPLPCaptcha = new PhpLPCaptcha('', 200, 60);
            SmartyValidate::register_object('PHPLPCaptcha', $PHPLPCaptcha);
            SmartyValidate::register_criteria('ValidCaptcha','PHPLPCaptcha->Validate');

         // register our validators
         SmartyValidate::register_validator('linkname', 'linkname', 'notEmpty',
            false, false, 'trim');
         SmartyValidate::register_validator('linkemail_empty', 'linkemail', 'notEmpty',
            false, false, 'trim');
         SmartyValidate::register_validator('linkemail_valid', 'linkemail', 'isEmail', false,
            false, 'trim');
         SmartyValidate::register_validator('linkcat', 'linkcat', 'notEmpty',
            false, false, 'trim');
         SmartyValidate::register_validator('linktitle', 'linktitle', 'notEmpty',
            false, false, 'trim');
         SmartyValidate::register_validator('linktitle_length', 'linktitle:1:45', 'isLength',
            false, false, 'trim');
         SmartyValidate::register_validator('linkurl', 'linkurl', 'notEmpty',
            false, false, 'trim');
         SmartyValidate::register_validator('linkurl_valid', 'linkurl', 'isURL',
            false, false, 'trim');
         SmartyValidate::register_validator('linkdescr', 'linkdescr', 'notEmpty',
            false, false, 'trim');
         SmartyValidate::register_validator('linkdescr_length', 'linkdescr:1:255', 'isLength',
            false, false, 'trim');
         // display form
         $smarty->display('submit_form.tpl');
      } else {   
         // validate after a POST
         SmartyValidate::connect($smarty);

         if(SmartyValidate::is_valid($_POST)) {
            // no errors, done with SmartyValidate
          $result = '<span class="OK">Thank you for submitting your Link to our Directory.<br />
            Your Link will be verified manually.<br />Meanwhile, Submit another Link.</span>';
          $smarty -> assign('result', $result);
          $smarty -> assign('fatal', false);
          $fatal = false;
          $smarty -> display('submit_form.tpl');
         
         } else {
            // error, redraw the form
            $smarty->assign($_POST);
            $result = '<span class="error">One or more errors were found, please correct them and try again.</span>';
            $smarty->assign('result', $result);
            $smarty->assign('fatal', true);
            $fatal = true;
            $smarty->display('submit_form.tpl');
         }
         
      }


and yes, "function" Validate DOES exist in Class "PhpLPCaptcha" :

Structure of Class:

Code:
class PhpLPCaptcha {
......
.....
.......
     function Validate($Input_Code, $CaseInsensitive = true) {
     .......
     }
}
Back to top
View user's profile Send private message
newname
Smarty Rookie


Joined: 25 May 2008
Posts: 26

PostPosted: Tue May 27, 2008 9:51 am    Post subject: Reply with quote

any help there?
Back to top
View user's profile Send private message
newname
Smarty Rookie


Joined: 25 May 2008
Posts: 26

PostPosted: Wed May 28, 2008 8:13 am    Post subject: Reply with quote

huh, this plugin SUCKS it has loads of bugs.
I dont think there is anything wrong with my CODE,
it is the stupid buggy plugin.
you own documentation's example of register_criteria with object doesnt even work.
what kind of document is it ? whats the point of a function that doesnt work even with its own example ??
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed May 28, 2008 2:19 pm    Post subject: Reply with quote

Don't use that stupid buggy stuff then. Write your own.
Back to top
View user's profile Send private message Visit poster's website
newname
Smarty Rookie


Joined: 25 May 2008
Posts: 26

PostPosted: Wed May 28, 2008 5:32 pm    Post subject: Reply with quote

I did write my own, but as I said above, I wanted something professional Smile
all of above was a post to attract your attention, as I saw, you werent fixing the bug ( it is a bug indeed )
to prove it, I used your documentation :
[PHP]
class test {

var $a = 'say';

function say($param)
{
if ($this -> a == 'say')
{
echo $param;
}
return true;
}

}
[/PHP]

My smarty validation code :

[PHP]
$test = new test;
if (empty($_POST['submit'])) {

SmartyValidate::connect($smarty, true);
SmartyValidate::register_object('test', $test);
SmartyValidate::register_criteria('Say','test->say');
SmartyValidate::register_validator('v_say','say','Say',false,false,'trim');
$smarty->display('form.tpl');
} else {
// validate after a POST
SmartyValidate::connect($smarty);

if(SmartyValidate::is_valid($_POST) && $fatal != true) {
// no errors, done with SmartyValidate
$smarty -> display('form.tpl');
} else {
// error, redraw the form
$smarty->assign($_POST);
$smarty->display('form.tpl');
}

}[/PHP]

My form.tpl :

[PHP]
<form method="POST" action="">
{validate id="v_say" criteria="Say" message="error"}
<input type="text" name="say" />
<input type="submit" name="submit" value="submit" />
</form>
[/PHP]

But everytime I use this form , it triggers this error:

Code:

Notice: SmartyValidate: [is_valid] method 'say' is not valid for object 'test'. in D:\**********\smarty\SmartyValidate.class.php on line 604


Any idea why I am getting this error ?? :s
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed May 28, 2008 8:45 pm    Post subject: Reply with quote

Try doing this:

Code:
SmartyValidate::register_object('test', $test);


Register the object every time the page loads, even after a form is submitted. Your object itself is not serialized into the session, you have to register it with each connect().
Back to top
View user's profile Send private message Visit poster's website
newname
Smarty Rookie


Joined: 25 May 2008
Posts: 26

PostPosted: Thu May 29, 2008 9:37 am    Post subject: Reply with quote

Okay Very Happy now its working Very Happy
thanks :d Love you sooooo much and love this plugin soooo much.. it made my coding much easier Smile

sorry for my post above insulting the plugin, but as I said, i didnt mean it, it was just to attract your attention Smile
sorry again for that Sad

ok now, this is my code :

Code:
class test {

   var $a = 'say';

   function say($param)
   {
      if ($this -> a == $param)
      {
         echo $param;
         return true;
      } else {
         return false;
      }
   }
}

$test = new test;
if (empty($_POST['submit']))
{
   SmartyValidate::connect($smarty, true);
   SmartyValidate::register_object('test', $test);
   SmartyValidate::register_criteria('Say','test->say');
   SmartyValidate::register_validator('v_say','say','Say', false,false,'trim');
   $smarty->display('form.tpl');
} else {
   // validate after a POST
   SmartyValidate::connect($smarty);
   SmartyValidate::register_object('test', $test);

   if(SmartyValidate::is_valid($_POST) && $fatal != true)
   {
      // no errors, done with SmartyValidate
      $smarty -> display('form.tpl');
   } else {
      // error, redraw the form
      $smarty->assign($_POST);
      $smarty->display('form.tpl');
   }
}


how do I verify two text fields ??
like if $param1 == $param2 return true .. else return false ???

what do I write in SmartyValidate::register_validator('v_say','say','Say', false,false,'trim'); ??
and in tpl file inplace of {validate id="v_say" message="asdasdasdasdasd"} ?

what what are these supposed to mean :

false,false,'trim' ??
I know trim clears the empty spaces in the $_POST but what about false, false ?


Thanks for the help sir Smile
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu May 29, 2008 2:54 pm    Post subject: Reply with quote

newname wrote:

how do I verify two text fields ??
like if $param1 == $param2 return true .. else return false ???


Write a custom validator that compares them. You have all of the form variables available in the validator.
Back to top
View user's profile Send private message Visit poster's website
newname
Smarty Rookie


Joined: 25 May 2008
Posts: 26

PostPosted: Thu May 29, 2008 3:17 pm    Post subject: Reply with quote

huh ! i could work out that much myself, use custom validator that compares them.. but how do i use it ? :s

I already tried, but it does NOT work !


class test {

function say($param, $param2)
{
if ($param == $param2)
{
echo "success";
return true;
} else {
return false;
}
}
}

$test = new test;

now what do I write in the register_validator function ?

I tried this:
SmartyValidate::register_object('test', $test);
SmartyValidate::register_criteria('Say','test->say');
SmartyValidate::register_validator('v_say','say:say2','Say', true,false,'trim');

but it does NOT work !


the form.tpl :

<td class="field">
<form method="POST" action="">
<input name="say" type="text" />
<input name="say2" type="text" />
<input type="submit" name="submit" value="submit" />
</form>
</td>

{validate field="say:say2" criteria="Say" message="asdasdasdasdasd"}


again i say, it does NOT work when we compare 2 fields...
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu May 29, 2008 7:48 pm    Post subject: Reply with quote

Actually, there is a validator that will compare two fields. from the docs:

Code:
SmartyValidate::register_validator('v_pass','pass:pass2','isEqual'); 


Otherwise when creating your own validators, please follow the rules in the docs:

Code:
function check_pass($value, $empty, &$params, &$formvars) { ... }


function say($param, $param2) is just flat wrong, it won't work.
Back to top
View user's profile Send private message Visit poster's website
newname
Smarty Rookie


Joined: 25 May 2008
Posts: 26

PostPosted: Fri May 30, 2008 7:09 am    Post subject: Reply with quote

what are these supposed to mean :
$value, $empty, &$params, &$formvars

??
and you also skipped many questions above.

my funciton ischeckRecip($siteurl, $recip) { .... }
one param is taken from the form and other is provided by user..
the function is called by this method :

checkRecip($_POST['linkrecip'], 'www.somesite.com')

this function checks the POST parameter on somesite.com ..
how can I call this function using smarty ?

this isnt working:
SmartyValidate::register_validator('v_recip','linkrecip','isRecip');

already registered the criteria stuff..
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri May 30, 2008 1:51 pm    Post subject: Reply with quote

newname wrote:
what are these supposed to mean :
$value, $empty, &$params, &$formvars


Read the documentation.

http://www.phpinsider.com/php/code/SmartyValidate/
Back to top
View user's profile Send private message Visit poster's website
newname
Smarty Rookie


Joined: 25 May 2008
Posts: 26

PostPosted: Fri May 30, 2008 2:49 pm    Post subject: Reply with quote

dont you have any answer for any of my question above?
your documentation isnt good, I already said that.
It doesnt asnwer any of the question I asked, why would I ask you if i could just read the docs? ofcourse I read the docs about 2 times, and couldnt find what the heck is false, false, trim in register_validator function, nor does it explain any thing about $vaue $empty $param and $form

what about the 2 text fields validation ?
I asked :
my funciton ischeckRecip($siteurl, $recip) { .... }
one param is taken from the form and other is provided by user..
the function is called by this method :

checkRecip($_POST['linkrecip'], 'www.somesite.com')

this function checks the POST parameter on somesite.com ..
how can I call this function using smarty ?

this isnt working:
SmartyValidate::register_validator('v_recip','linkrecip','isRecip');

already registered the criteria stuff..

why do you waste your time posting incomplete messages? :s you can save your time as well as others by posting all the answers in one single post instead of ignoring half of questions ( I read it somewhere else too, somone suggested you to make single post instead of 4 )
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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