How can we check a form field with a database table column. For example I want to restrict registration of a person if he registered before. I want ChronoForm to check NationalID that person entered with all NationalIDs in database and show a mesaage.
Please Help
Please Help
Hi hoomijoon,
You can do this after the form is submitted using custom Serverside Validation (you use the Event Switcher action for this in CFv5). I would add a simple MySQL query there to check for an existing record.
It's more complicated but you could also use JavaScript and AJAX to add a Client-side validation as well (note that this should be in addition to the server side check).
Bob
You can do this after the form is submitted using custom Serverside Validation (you use the Event Switcher action for this in CFv5). I would add a simple MySQL query there to check for an existing record.
It's more complicated but you could also use JavaScript and AJAX to add a Client-side validation as well (note that this should be in addition to the server side check).
Bob
Thanks Bob
I used this code in Event Switcher:
<?php
$db =& JFactory::getDBO();
$query = "
SELECT `id`
FROM `sm25o_chronoengine_chronoforms_datatable_register`
WHERE `nationalcode` = '0081501277' ;
";
$db->setQuery($query);
$options = $db->loadAssocList();
if ($options) {
echo 'fail';
}else{
echo 'success';
}
?>
But I get this ERROR:
Strict Standards: Only variables should be assigned by reference in /var/www/html/administrator/components/com_chronoforms5/chronoforms/actions/event_switcher/event_switcher.php(26) : eval()'d code on line 2 fail
I used this code in Event Switcher:
<?php
$db =& JFactory::getDBO();
$query = "
SELECT `id`
FROM `sm25o_chronoengine_chronoforms_datatable_register`
WHERE `nationalcode` = '0081501277' ;
";
$db->setQuery($query);
$options = $db->loadAssocList();
if ($options) {
echo 'fail';
}else{
echo 'success';
}
?>
But I get this ERROR:
Strict Standards: Only variables should be assigned by reference in /var/www/html/administrator/components/com_chronoforms5/chronoforms/actions/event_switcher/event_switcher.php(26) : eval()'d code on line 2 fail
Hi hoomijoon,
Please take the & out of this line in Joomla! 3 $db =& JFactory::getDBO();
And I wouldn't advise running any site with Strict Standards reporting on :-(
Bob
Please take the & out of this line in Joomla! 3 $db =& JFactory::getDBO();
And I wouldn't advise running any site with Strict Standards reporting on :-(
Bob
Thank you so much...
How can I replace '0081501277' in this code with a form value that user entered?
How can I replace '0081501277' in this code with a form value that user entered?
Hi hoomijoon,
Yes, like this
Bob
Yes, like this
WHERE `nationalcode` = '{$form->data['input_name']}' ;You may also want to add some validation to make sure that the input has a value set before running the query.
Bob
Thanks Bob,
but another problem: as you see in my code I used echo to determine which action should be performed after form submition. but program just echos: fail or success on the screen. I used a 'display message' block in fail event !
but another problem: as you see in my code I used echo to determine which action should be performed after form submition. but program just echos: fail or success on the screen. I used a 'display message' block in fail event !
This topic is locked and no more replies can be posted.
