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

SmartyValidate suggested control structure

 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
Noraz
Smarty Rookie


Joined: 12 Aug 2004
Posts: 13
Location: Raleigh, NC

PostPosted: Thu Aug 12, 2004 6:18 pm    Post subject: SmartyValidate suggested control structure Reply with quote

I have a report to write, which requires some input from the user before being ran, e.g. date ranges and selecting data pulled from a DB. I'm using SmartyValidate to validate the user's selections/input.

My first thought was to have 2 sets of files
filter.php - filter.tpl
report.php - report.tpl

but I'm wondering if it's better to have a only a single php file as in
report.php - filter.tpl and report.tpl

What are your opinions on the two control structures below? Is there a better way to do this? an article I can be pointed to?

A) Note, I'm not sure how to redirect to a php file in this scenario...
Code:

// filter.php
if(empty($_POST)) {

   // Gather filter data from the database here

   SmartyValidate::register_form('filterForm', true);     
   $smarty->display('filter.tpl');
} else {
   // validate after a POST
   if(SmartyValidate::is_valid($_POST,'filterForm')) {
       // no errors, done with SmartyValidate
       SmartyValidate::disconnect();

      // Redirect to report.php?
      // Can I retain form selections?

   } else {
       // error, redraw the form
       $smarty->assign($_POST);
       $smarty->display('filter.tpl');
   }
}

//report.php
// Gather report data from the database here
$smarty->display('report.tpl');


B) Gather data all in a single file...
Code:

// filter.php
if(empty($_POST)) {

   // Gather filter data from the database here

   SmartyValidate::register_form('filterForm', true);     
   $smarty->display('filter.tpl');
} else {
   // validate after a POST
   if(SmartyValidate::is_valid($_POST,'filterForm')) {
       // no errors, done with SmartyValidate
       SmartyValidate::disconnect();

      // Gather report data from the database here

      $smarty->display('report.tpl');

   } else {
       // error, redraw the form
       $smarty->assign($_POST);
       $smarty->display('filter.tpl');
   }
}


I'm new to PHP and Smarty, but I'd like to do things in a standard sort of fashion. Of course neither of these ways may be acceptable.

Thanks for your comments and help.
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
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