Hi,
I have a form with a field code, for server side validation I use the following script:
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
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
Hi loli,
Try changing the message here
Bob
Try changing the message here
$messages[] = "Sorry! Code is already used";
Bob
I replaced by:
What should I do to change the script to display the error message:
code does not exist in our database
Thank you
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
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
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
Hi loli,
Then at the end add this extra code
Bob
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
Hi Bob,
my script works but I'm trying to modify it to get another error message:

Thank you
<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
Hi Loli,
I removed a lot of extra spaces:
Bob
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
Hi Loli,
Then we are back to changing the message in this line
I'm clearly missing something here as I have less and less idea what you are asking.
Bob
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
how can I make a validation like this?

I tried
but it did not work😲
I hope I was clear enough
Thank you for your help

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
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
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
Hi Bob,
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
<?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
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:
/Fredrik
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
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
This topic is locked and no more replies can be posted.