Smarty Help

Discussion in 'PHP' started by nastynappy, May 27, 2008.

  1. #1
    I am a PHP Coder.
    But I just started using Smarty with Smarty Validation Plugin, for the development of my new Link Directory Software.
    I am stuck at something.
    its captcha validation.
    I am giving you an example of my code here :
    
    class test {
    
    	var $a = 'say';
    
    	function say($param)
    	{
    		if ($this -> a == 'say')
    		{
    			echo $param;
    		}
    		return true;
    	}
    
    }
    
    PHP:
    My smarty validation code :

    
    $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 :

    
    <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:

    
    Notice: SmartyValidate: [is_valid] method 'say' is not valid for object 'test'. in D:\**********\smarty\SmartyValidate.class.php on line 604
    
    Code (markup):
    Any idea why I am getting this error ?? :s
    I figured out that it means method 'say' doesnt exist in class 'test' ( anyone can figure out that much :p LOL ) but this isnt true :confused:
    Please help me :(
     
    nastynappy, May 27, 2008 IP
  2. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #2
    Isn't the validator looking for v_say's value? Your input is returning a value for "say"

    Of course, I haven't looked at SmartyValidate in about 2 years. :shrug: So don't take my word for it, unless it works. :)

    cheers,

    gary
     
    kk5st, May 27, 2008 IP
  3. nastynappy

    nastynappy Banned

    Messages:
    499
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #3
    huh, there is nothing wrong with the validator's code.
    it is the right way to do it, but for some reason it doesnt work.
    i think it is a bug. and i thought you knew how to fix it, but i was wrong..
    anyway, thanks for reply.. but i was expecting a useful reply :(
     
    nastynappy, May 28, 2008 IP
  4. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #4
    No, not with the validator code. I was thinking that this
    
    <input type="text" name="say" />
    Code (markup):
    should be
    
    <input type="text" name="v_say" />
    Code (markup):
    gary
     
    kk5st, May 28, 2008 IP
  5. nastynappy

    nastynappy Banned

    Messages:
    499
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #5
    nope it shouldnt be v_say, again I am saying, my tpl file is 100% correct :) , read their documentation again please :)

    Update : ah, figured it out, i just had to add register_object after the next connect too :p
    thanks for your time though..
     
    nastynappy, May 29, 2008 IP