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

SmartyValidate: Using the same criteria but different param

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


Joined: 06 Mar 2004
Posts: 33

PostPosted: Sun Dec 05, 2004 11:51 am    Post subject: SmartyValidate: Using the same criteria but different param Reply with quote

I created this custom critera to check if a field exist in a database:

[php:1:7e0dd49665]
function mbr_isExist ($value, $empty, &$params, &$formvars)
{
// check if required parameters are not empty
if (!isset($params['column']) || !isset($params['table']))
{
trigger_error("SmartyValidate: [mbr_isExist] parameter 'column' or 'table' is missing.");
return false;
}
// prepare query
$query = "SELECT {$params['column']} FROM {$params['table']} WHERE {$params['column']} = '$value'";
// query database
$result = mysql_query($query) or die(mbr_mysql_error(__LINE__));
// return result
return (mysql_num_rows($result) > 0) ? false : true;
}
[/php:1:7e0dd49665]

Usage:
Code:

<input type="text" name="username" />

{validate form="myform" field="username" criteria="mbr_isExist" column="str_username" table="tbl_users" transform="trim" message="..."}


This works fine, but when you use the same criteria more than once and used a different parameter value, it doesn't work anymore.

Sample problem:
Code:

<input type="text" name="username" />

{validate form="myform" field="username" criteria="mbr_isExist" column="str_username" table="tbl_users" transform="trim" message="..."}

{validate form="myform" field="username" criteria="mbr_isExist" column="str_username" table="tbl_admin" transform="trim" message="..."}


As you can see in the 2nd time I used the "mbr_isExist" critera, I used a different value in the "table" parameter.

When this is actually tested, the first usage of mbr_isExist works (meaning, if the field exist in "tbl_users" it returns an error msg)
But on the 2nd usage of mbr_isExist, it doesn't work anymore (meaning, if the field exist in "tbl_admin" it doesn't return an error msg anymore)

What could be the problem?
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