Forums

ServerSide Validation not executed

ECH 26 Jun, 2010
Hi,
I got a problem on CF_V3.1_RC5.5 installed on Joomla 1.5.18, it appears the php code in the ServerSide Validation is not executed

heres the configuration of the "Validation" tab page :

[JavaScript Live Validation]
Enable Validation -> YES
Validation Library -> Mootols
Run Validation onlyOnBlur -> YES
Waiting time -> (left blank)
Run Validation onlyOnSubmit -> YES
Validation Messages type -> default

[ServerSide Validation]
Enable -> YES

There is additionnal conditions in the php code, when i fill a form correctly for the JS verification, but wrong for the php verification (additional conditions), it is accepted anyway.
It looks like the php code is completly ignored

What did I do wrong ?🙂

Thanks
GreyHead 26 Jun, 2010
Hi ECH,

Please post the PHP Code you are using for the validation.

Bob
ECH 26 Jun, 2010
Hi Bob,

ty,
Heres the code, you'll see table names from the DB witch are not in the standard Joomla, these tables are however in the same DB, variable and comment are in french (the concerned website is in french by default.

Of course this code will be much longer, but for the moment i just try to make it run🙂
<?php
global $mainframe;

//recup des variables formulaire
$PrenomAvatar=JRequest::getvar('Av_Prenom');
$NomAvatar=JRequest::getvar('Av_Nom');

//Vérification du prenom avatar
if ((strlen($PrenomAvatar)<=3) or (strlen($PrenomAvatar)>=15)) {
	return'Le Prénom doit comporter entre 3 et 15 caractères';
	}
//Vérification de la disponibilité de l'identité
$ReqIdentity = mysql_query ("SELECT COUNT(*) as nbUser FROM users WHERE ((username='$PrenomAvatar') and (lastname='$NomAvatar'))");
$nbUser=mysql_fetch_array($ReqIdentity);
if ($nbUser['nbUser'] != 0) {	return'Cette identité est déjà utilisée';
				}
mysql_free_result($ReqIdentity);

?>
ECH 26 Jun, 2010
A little "UP"..

After you asked me the code, i had a doubt and retyped it. Now it works !! Could it be sensitive to some spaces in a wrong place ?
However, there's still a problem : the form variables are not transfered (JRequest::getvar...) is there a syntax error ? I already used it on other websites without any problems.

ty very much Bob
GreyHead 26 Jun, 2010
Hi ECH,

I think it needs to be getVar with a capital V (but I'm not certain). Here's how I would write your code using the Joomal DB syntax
<?php
//recup des variables formulaire
$PrenomAvatar = JRequest::getString('Av_Prenom', '', 'post');
$NomAvatar = JRequest::getString('Av_Nom', '', 'post');
if ( !$PrenomAvatar || !$NomAvatar ) {
  return "prénom et nom sont tenus";
}
//Vérification du prenom avatar
if ( strlen($PrenomAvatar) <= 3 || strlen($PrenomAvatar) >= 15 ) {
   return "Le Prénom doit comporter entre 3 et 15 caractères";
}
//Vérification de la disponibilité de l'identité
$db =& JFactory::getDBO();
$query = "
  SELECT COUNT(*)
    FROM `users` 
    WHERE `username` = $db->Quote($PrenomAvatar) 
      AND `lastname` = $db->Quote($NomAvatar) ;";
$db->setQuery($query);
if ( !$db->loadResult() ) {  
  return 'Cette identité est déjà utilisée';
}
?>

Bob
ECH 27 Jun, 2010
Sounds very nice, I'll try today using this syntax, closer from Joomla standard and a good way to learn more about🙂

Thank you very much for your help Bob :wink:
This topic is locked and no more replies can be posted.