Forums

(Résolu) server side validation

loli 02 Sep, 2011
Hi,
I have a form with a field code, for server side validation I use the following script:
<?php
$db =& JFactory::getDBO();
$code = JRequest::getString('text_0', '', 'post');
$query = "
SELECT COUNT(*)
FROM `jos_chronoforms_Passer_commande`
WHERE `text_0` = '$code' ;
";
$db->setQuery($query);
if ( $db->loadResult() ) {
$messages[] = "Sorry! Code is already used";
}
?>

but I wanted to change my script so that if a user adds a code that does not exist in the database that it displays the error message:
code does not exist in our database, please select a valid code

Thank you in advance for your help
GreyHead 02 Sep, 2011
Hi loli,

Try changing the message here
$messages[] = "Sorry! Code is already used";

Bob
loli 02 Sep, 2011
I replaced by:
return "Désolé code est déjà utilisé!";

What should I do to change the script to display the error message:
code does not exist in our database

Thank you
GreyHead 02 Sep, 2011
Hi loli,

Sorry I didn't realsie that the code you are using isn't complete.

Which version of ChronoForms are you using? You can find the version from Site Admin | Extensions | Install/Uninstall | Components in Joomla! 1.5 or Site Admin | Extensions | Extension Manager | Manage in Joomla! 1.6.

Bob
loli 02 Sep, 2011

Which version of ChronoForms are you using?
Bob


Chrono Contact V 3.2
GreyHead 02 Sep, 2011
Hi loli,

Then at the end add this extra code
$messages[] = "Sorry! Code is already used";
}
// add this bit
if ( count($messages) ) {
  $messages = implode('<br />', $messages);
  return $messages;
}
?>

Bob
loli 02 Sep, 2011
Hi Bob,
<Php? 
$ db = & JFactory:: getDBO (); 
$ code = JRequest:: getString ("text_0 ','',' post '); 
$ query = " 
SELECT COUNT (*) 
FROM `jos_chronoforms_Passer_commande` 
WHERE `text_0 `= '$ code'; 
"; 
$ db-> setQuery ($ query); 
if ($ db-> loadResult ()) { 
return "Désolé code est déjà utilisé";! 
} 
?>

my script works but I'm trying to modify it to get another error message:


Thank you
GreyHead 02 Sep, 2011
Hi Loli,

I'm sorry, I have not longer got any idea what the problem is.

Bob
loli 02 Sep, 2011
Hi Bob,
I wanted to do a script that checks if the code entered by the user exists in the database if it does not it displays the following error message
GreyHead 02 Sep, 2011
Hi Loli,

I removed a lot of extra spaces:
<?php
$db = & JFactory::getDBO ();
$code = JRequest::getString ("text_0','', 'post');
$query = "
  SELECT COUNT (*)
   FROM `#__chronoforms_Passer_commande`
   WHERE `text_0` = '{$code}';
";
$db->setQuery($query);
if ( $db->loadResult() ) {
  return "Désolé code est déjà utilisé !";
}
?>

Bob
loli 02 Sep, 2011
Hi Bob,

I wanted to get this result:


Thank you
GreyHead 02 Sep, 2011
Hi Loli,

Then we are back to changing the message in this line
  return "Désolé code est déjà utilisé !";


I'm clearly missing something here as I have less and less idea what you are asking.

Bob
loli 02 Sep, 2011
I'm sorry I'm not strong in English😶 ,
forget the old script
loli 02 Sep, 2011
how can I make a validation like this?


I tried
<Php? 
$ db = & JFactory:: getDBO (); 
$ code = JRequest:: getString ("text_0','', 'post'); 
$ query = " 
  SELECT COUNT (*) 
   FROM `# __chronoforms_Passer_commande` 
   WHERE ` text_0 `= '{$ code}'; 
"; 
$ db-> setQuery ($ query); 
if ($ db-> loadResult ()) { 
  return "Code does not exist in our database";! 
} 
?>

but it did not work😲

I hope I was clear enough
Thank you for your help
GreyHead 02 Sep, 2011
Hi lola,

The code you have looks correct to me.

Are the all the variable names correct? The table name and the input name from the form?

Bob
loli 03 Sep, 2011
Hi Bob,
<?php
$db =& JFactory::getDBO();

$code = JRequest::getString('text_55', '', 'post');
$query = "
SELECT COUNT(*)
FROM `jos_chronoforms_devenez_ambassadrice`
WHERE `text_55` = '$code' ;
";

$db->setQuery($query);
if ( $db->loadResult() ) {
return "Code does not exist in our database";
}
?>

the script works now, but it displays the error message even though the code exists in the database..
link to the form: http://www.instantrejouvence.com/index.php?option=com_chronocontact&Itemid=80&lang=fr

Thank you
loli 07 Sep, 2011
UP
nml375 07 Sep, 2011
Hi Bob & loli,
Just to pitch in, If you'd like the error to be shown if the code is NOT present in the database, you'll have to negate your test - or better, test it against 0:
...
if ($db->loadResult() == 0) {
...


/Fredrik
loli 08 Sep, 2011
it works, thank you very much Fredrik
loli 10 Sep, 2011

Hi Bob,

<?php
$db =& JFactory::getDBO();

$code = JRequest::getString('text_55', '', 'post');
$query = "
SELECT COUNT(*)
FROM `jos_chronoforms_devenez_ambassadrice`
WHERE `text_55` = '$code' ;
";

$db->setQuery($query);
if ( $db->loadResult() ) {
return "Code does not exist in our database";
}
?>


the script works now, but it displays the error message even though the code exists in the database..
link to the form: http://www.ouvence.com/index.php?option=com_chronocontact&Itemid=80&lang=fr

Thank you
GreyHead 16 Sep, 2011
Hi loli,

Is there a question here?

Bob
loli 17 Sep, 2011
Hi Bob,
non, it is a error,thank you
GreyHead 17 Sep, 2011
Hi Loli,

Should that be jouvence.com ????

I don't see the form anywhere there though?

Bob
This topic is locked and no more replies can be posted.