IT Community - Software Programming, Web Development and Technical Support

validate using smarty

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


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-28-2007, 04:27 AM
venkatbi venkatbi is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 80
venkatbi is on a distinguished road
Question validate using smarty

hi all,
how to validate a php file using smarty i.e..,without js

thanks in advance,
venkatbi
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-05-2007, 08:55 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: validate using smarty

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!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-05-2007, 08:57 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: validate using smarty

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!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 02:17 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0