This is a discussion on validate using smarty within the PHP Programming forums, part of the Web Development category; hi all, how to validate a php file using smarty i.e..,without js thanks in advance, venkatbi...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi... Here is sample code... Code: <?php
require_once( “Smarty.class.php” );
class registrationView
{
var $smarty;
var $model;
function registrationView( &$model, $template )
{
$this->smarty = new Smarty;
$this->model =& $model;
$this->setTemplate( $template );
}
function setTemplate( $formTplName = ‘registration’ )
{
$this->formTplName = $formTplName . “.tpl”;
if( is_file( “templates/” . $formTplName . “.php” ) )
{
include_once( “templates/” . $formTplName . “.php” );
$this->fields = $fields;
}
else
{
$this->fields = array();
}
}
function display()
{
$this->smarty->assign( “fields”, $this->fields );
$this->smarty->assign( “form”, $this->model->getFormValues() );
$this->smarty->assign( “error”, $this->model->getErrorValues() );
$this->smarty->display( $this->formTplName );
}
}
class registrationModel
{
var $form;
var $db;
function registrationModel( &$form )
{
$this->db = new DB_Tsc;
$this->form = $form;
}
function getFormValues()
{
return $this->form;
}
function getErrorValues()
{
return $this->error;
}
function validateForm()
{
$ret = true;
if( is_array( $this->form ) )
{
reset( $this->form );
foreach( $this->form as $key => $val )
{
if( $val == ” )
{
$this->error[ $key ] = true;
$ret = false;
}
}
}
else
{
$this->error[ ‘warning’ ] = “Please complete the form”;
$ret = false;
}
return $ret;
}
function saveForm()
{
}
}
class RegistrationController
{
var $view;
var $model;
var $page;
function RegistrationController( $page, &$form )
{
$this->page = $page;
$this->model = new registrationModel( $form );
$this->view = new registrationView( $this->model, “registration” );
}
function main()
{
switch( $this->page )
{
case “validate”:
if( $this->model->validateForm() )
{
$this->model->saveForm();
$this->view->setTemplate( ‘thankyou’ );
}
$this->view->display();
break;
default:
$this->view->display();
break;
}
}
}
$t = new RegistrationController( $page, $form );
$t->main();
?>
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| For more visit the following links.... ![]() Validate.PHP for Smarty Smarty : Show Source Computers Software Php USING SMARTY - Amazines.com Article Search Engine Learn with my posts.... ![]()
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to use smarty variables in javascript? | sureshbabu | PHP Programming | 1 | 03-31-2008 02:48 AM |
| Drawback in smarty | sureshbabu | PHP Programming | 0 | 03-28-2008 06:03 AM |
| Smarty | sureshbabu | PHP Programming | 19 | 09-29-2007 01:36 AM |
| How to Validate IPAddress using C#? | kingmaker | C# Programming | 1 | 07-24-2007 06:00 AM |
| Smarty | Jeyaseelansarc | PHP Programming | 3 | 05-16-2007 06:35 AM |