Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

How to use SmartyValidate inside smarty plugin OOP style

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
moggen_83
Smarty Rookie


Joined: 06 Sep 2005
Posts: 5
Location: sweden

PostPosted: Tue Sep 20, 2005 5:07 pm    Post subject: How to use SmartyValidate inside smarty plugin OOP style Reply with quote

I have tried for a while to use SmartyValidate inside my class in my Smarty plugin and have found a way to do this. If any one have a smarter way to do this please come with a comment. And hear is the code:

// function.load_foo.php
require_once(SMARTY_DIR.'SmartyValidate.class.php');
function smarty_function_load_foo($params, $smarty)
{
$myFoo = new Foo(&$params,&$smarty);
$myFoo->init();
//assign template variable
$smarty->assign($params['assign'], $foo);
}
class Foo
{


function __construct($params,$smarty)
{
if(empty($_POST))
{
SmartyValidate::connect($smarty, true);
SmartyValidate::register_validator('fname','FullName','notEmpty');
SmartyValidate::register_validator('fdate','Date','isDate');

}
else
{
SmartyValidate::connect($smarty);
// validate after a POST
if(SmartyValidate::is_valid($_POST)) {
// no errors, done with SmartyValidate
SmartyValidate::disconnect();
//readirect
header("Location: index.php?success");
}
else
{
//Error redraw from
$smartObject->assign($params['assign'],$_POST);
}
}
}

function init()
{


}
}

// foo.tpl

{load_foo assign="foo"}
<form method="POST" action="index.php?Test">

{validate id="fname" message="Full Name cannot be empty"}
Full Name: <input type="text" name="FullName">

{validate id="fdate" message="Date is not valid"}
Date: <input type="text" name="Date">

<input type="submit">

</form>
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 -> Tips and Tricks All times are GMT
Page 1 of 1

 
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