how to put a duplicate error? if there is already a record in the database..for example i input a username and it was recorded in the databses, now if i input that username again, there must be an error prompt to the user.. how can i do this..?? please help....
Forums
how to put a duplicate error?
Hi donna22,
This is a good case for an AJAX check to make sure that the username is unique. I think that someone posted an example here.
Or you can use ChronoForms server-side validation to do a quick database lookup.
Bob
This is a good case for an AJAX check to make sure that the username is unique. I think that someone posted an example here.
Or you can use ChronoForms server-side validation to do a quick database lookup.
Bob
Hi donna22,
Severside validation works after the form is submitted. In ChronoForms there is a box on the Validation tab where you can enter code to do a validation check. For this the code would be something like this:
Bob
Severside validation works after the form is submitted. In ChronoForms there is a box on the Validation tab where you can enter code to do a validation check. For this the code would be something like this:
<?php
$username =& JRequest::getString('uername', '', 'post');
if ( $username = '' ) {
return "You must enter a username";
}
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(username)
FROM `#__some_database_table`
WHERE `username` = $username;";
$db->setQuery($query);
if ( $db->loadResult() > 0 ) {
return "Username is already in use";
}
?>
Note: not tested and may need de-bugging!Bob
great! ill try this one first then ill give you feedback with the result..
;)
;)
Bob.,
it returns non error; i tried to debug it..tried to modify it, but still no prompt error and still send into the database,,,...
any help?
it returns non error; i tried to debug it..tried to modify it, but still no prompt error and still send into the database,,,...
any help?
here is the code:
<?php
$username =& JRequest::getString('username', '', 'post');
if ( $username = '' ) {
return "You must enter a username";
}
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(username)
FROM `jos_chronoforms_uname`
WHERE `username` = $username;";
$db->setQuery($query);
if ( $db->loadResult() > 0 ) {
return "Username is already in use";
}
?>
Hi donna22,
I suspect that the query is failing and I think you may need quotes round the value. Please try this, if it doens't work we'll add some diagnostics.
Bob
I suspect that the query is failing and I think you may need quotes round the value. Please try this, if it doens't work we'll add some diagnostics.
<?php
$username =& JRequest::getString('username', '', 'post');
if ( $username = '' ) {
return "You must enter a username";
}
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(username)
FROM `jos_chronoforms_uname`
WHERE `username` = ".$db->quote($username).";";
$db->setQuery($query);
if ( $db->loadResult() > 0 ) {
return "Username is already in use";
}
?>
Bob
Hi. I'm just starting with ChronoForms and i have a question. How to re-write this code to check "text_2" from the table? If already exist it will put error.
Hi Jarek,
If you need to do the same function of the code above (username check) then there is a better way with the latest release but to do what you need here is a code sample:
Cheers
Max
If you need to do the same function of the code above (username check) then there is a better way with the latest release but to do what you need here is a code sample:
$query = "
SELECT text_2
FROM `jos_chronoforms_uname`
WHERE `username` = ".$db->quote($username).";";
$db->setQuery($query);
if ( $db->loadResult() > 0 ) {
return "text_2 already exists";
}
Cheers
Max
Thank you so much. But can you write this better way? In this I do something wrong. I have now v3.1 RC5 release of ChronoForms.
Hi Jarek,
Ok, first please get the official RC5.1
you need this code in the Joomla registration plugin after submit box:
The code above will stop the form if there is an error and will show the error you got whatever it was!
Cheers
Max
Ok, first please get the official RC5.1
you need this code in the Joomla registration plugin after submit box:
<?php
$MyForm =& CFChronoForm::getInstance('form name');
$MyPlugins =& CFPlugins::getInstance($MyForm->formrow->id);
if($MyPlugins->cf_joomla_registration['errors']){
$MyForm->formerrors = $MyPlugins->cf_joomla_registration['errors'];
return;
}
?>
The code above will stop the form if there is an error and will show the error you got whatever it was!
Cheers
Max
This topic is locked and no more replies can be posted.