|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
jnewing Smarty n00b
Joined: 09 Nov 2006 Posts: 2
|
Posted: Thu Nov 09, 2006 8:13 pm Post subject: Need a Bit Of Help |
|
|
Ok so here is my Code.
Code: |
require_once('../lib-conf/mv2_dist_conf.php');
require_once(api . '/AdminLib.php');
//###########################################
//# Create Obj(s)
//###########################################
$alib = new AdminLib_Manage_Admins();
$valid = new SmartyValidate();
$_orderby = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'lastname';
$_sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'desc';
$_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$_tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : 'add';
//###########################################
//# Preform Actions
//###########################################
switch ($_action) {
case 'do_add':
// stuff here
break;
default:
// more stuff here
break;
}
//###########################################
//# Set Pages Validation
//###########################################
switch ($_tab) {
case 'manage': // ============== Manage Admins Tab ===
$alib->GetAdmins('admins', $_orderby, $_sort);
if (empty($_POST)) {
$valid->connect($alib->_tpl, true);
$valid->register_validator ('AdminIds', 'admin_ids', 'notEmpty');
$valid->register_validator ('AdminAction', 'admin_action', 'notEmpty');
} else {
$valid->connect($alib->_tpl);
if ($valid->is_valid($_POST)) {
// Valid Form Fields
$valid->disconnect();
$alib->_tpl->assign('success', 'Administrator(s) were successfully updated.');
} else {
// Invalid Form Fields
$alib->_tpl->assign($_POST);
}
}
break;
case 'edit': // ============== Edit Admins Tab ===
$alib->GetAdmins('admins', $_orderby, $_sort);
break;
case 'add': // ============== Add Admins Tab ===
default:
if (empty($_POST)) {
$valid->connect($alib->_tpl, true);
$valid->register_validator ('UserName', 'username', 'notEmpty');
$valid->register_validator ('Passwords', 'password:password_again', 'notEmpty');
$valid->register_validator ('Passwords', 'password:password_again', 'isEqual');
$valid->register_validator ('Email', 'email', 'notEmpty');
$valid->register_validator ('Email', 'email', 'isEmail');
} else {
$valid->connect($alib->_tpl);
if ($valid->is_valid($_POST)) {
// Valid Form Fields
$valid->disconnect();
$alib->_tpl->assign('success', 'Admin was successfully added to the database.');
} else {
// Invalid Form Fields
$alib->_tpl->assign($_POST);
}
}
break;
}
$alib->_tpl->display('manage_admins.tpl');
|
Now everything works fine but when I add and admin this is the error i get after the admin is added. this erros does not occure when the user is adding the admin etc.. only after the admin has been added. I have included sreenshots below.
Befor the Add
-----------------
After The Add Was Successful
-----------------------------------
For the life of me I can't figure out why this error is getting produced. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Nov 09, 2006 9:16 pm Post subject: |
|
|
Try commenting out
Code: | //SmartyValidate::disconnect(); |
If that does it, you're probably wiping out your session data with disconnect() and then not calling connect($smarty,true) and re-registering validators afterwards. |
|
Back to top |
|
jnewing Smarty n00b
Joined: 09 Nov 2006 Posts: 2
|
Posted: Thu Nov 09, 2006 9:50 pm Post subject: lol |
|
|
thanks for that, I had just figured that out and came back to say nvm when i read what you said
so thanks awesome addon btw SmartyValidator rocks.
Just for an idea i would like to see something where i could do something as follows.
<form name="myForm" action="blah" method="blah">
<input type="text" name="name" {validate chk="notEmpty"}
etc...
</form>
and then All i would have to call is
SmartyValidator::connect($smartyconnection);
SmartyValidator::validate('myForm');
and maybe would return 'true' if the form was valid or an array with the invalid fields, or smarty data etc.. something.. Then my template coders could do the form checking.
I don't know if that makes total sense, my english is not the best. |
|
Back to top |
|
mikan Smarty n00b
Joined: 17 Nov 2006 Posts: 2
|
Posted: Fri Nov 17, 2006 1:45 am Post subject: |
|
|
Hi,
I'm new to smarty and I'm also having a problem validating multiple pages. Here's my code. Please help. It doesn't seems to read the empty($_POST).
$page is a hidden field in the templates.
Edit: Problem solved.
Code: |
$page = $_REQUEST['page'];
switch ($page)
{
case "1":
if(empty($_POST))
{
echo "form1<br>";
SmartyValidate::connect($smarty, true);
SmartyValidate::set_page('1');
SmartyValidate::register_validator('number', 'number', 'notEmpty');
$smarty->display('testing1.tpl');
}
else
{
SmartyValidate::connect($smarty);
if (SmartyValidate::is_valid($_POST))
{
//This is where I do my business
$number = $_POST['number'];
$smarty->assign('number', $number);
//Go to the success screen
SmartyValidate::connect($smarty, true);
SmartyValidate::set_page('2');
SmartyValidate::register_validator('name', 'name', 'notEmpty');
$page= 2;
$smarty->assign('page', $page);
$smarty->display('testing2.tpl');
}
else
{
$smarty->assign($_POST);
//SmartyValidate::set_page('1');
$smarty->display('testing1.tpl');
}
}
break;
case "2":
if(empty($_POST))
{
//$page= $_POST['page'];
echo "form2<br>";
//echo "hello alyssa<br>";
SmartyValidate::connect($smarty, true);
SmartyValidate::set_page('2');
SmartyValidate::register_validator('name', 'name', 'notEmpty'); $smarty->display('testing2.tpl');
}
elseif (!empty($_POST))
{
SmartyValidate::connect($smarty);
if (SmartyValidate::is_valid($_POST))
{
//This is where I do my business
$name = $_POST['name'];
$smarty->assign('name', $name);
//Go to the success screen
$smarty->display('home.tpl');
}
else
{
$smarty->assign($_POST);
//SmartyValidate::set_page('1');
$smarty->display('testing2.tpl');
}
}
break;
default:
SmartyValidate::set_page('1');
$smarty->display('testing1.tpl');
}//end switch case
|
|
|
Back to top |
|
NoWhereMan Smarty Rookie
Joined: 14 Feb 2006 Posts: 15
|
|
Back to top |
|
|
|
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
|
|