Hi Bob and Chrono Forms Community!
I've made a Form and I need it to be submited only once per joomla user.
So, I made the userid field UNIQUE in my new table (that stores the information of the chronoform).
My question is, if I can personalize the SQL error that appears when I try to submit the form more than once.
Now it looks like: "(...)store failed - Duplicate entry '69' for key 2 SQL=INSERT INTO `jos_chronoforms_(...)"
Thanks a lot!
Marina
I've made a Form and I need it to be submited only once per joomla user.
So, I made the userid field UNIQUE in my new table (that stores the information of the chronoform).
My question is, if I can personalize the SQL error that appears when I try to submit the form more than once.
Now it looks like: "(...)store failed - Duplicate entry '69' for key 2 SQL=INSERT INTO `jos_chronoforms_(...)"
Thanks a lot!
Marina
Hi Marina,
You need to put the check at the beginning of the Form HTML to see if the user has already responded. I posted some very similar code in the last few days.
Your check is working but it's really too late by the time the form is submitted.
Bob
You need to put the check at the beginning of the Form HTML to see if the user has already responded. I posted some very similar code in the last few days.
Your check is working but it's really too late by the time the form is submitted.
Bob
Sorry to dig this old post up, but it same up in the search I ran and I couldn't find the code you referred to in your post.
Could you advise on how is best to prevent unique violoations occuring resulting in the same error?
Could you advise on how is best to prevent unique violoations occuring resulting in the same error?
Hi srthomas,
What exactly do you want to check for?
I think that the question in this thread was about editing existing data - in that case you need to make sure that the record primary key is included in the form as a hidden input. It will be something like:
Bob
What exactly do you want to check for?
I think that the question in this thread was about editing existing data - in that case you need to make sure that the record primary key is included in the form as a hidden input. It will be something like:
<input type='hidden' name='cf_id' id='cf_id' value='<?php echo $cf_id; ?>' /> Bob
I have a field that I have marked as UNIQUE in the table definition called "Category". Previous to changing the table definition the form allowed you to enter the same category time after time. I stopped this by setting the UNIQUE property on the column.
Now I get an error on the page after submit "store failed - Duplicate entry ..."
What do you suggest?
Now I get an error on the page after submit "store failed - Duplicate entry ..."
What do you suggest?
Hi srthomas,
I'm confused. I'd guess that you need to validate the form results to make sure that the Category is indeed unique, otherwise you'll get the error.
Bob
I'm confused. I'd guess that you need to validate the form results to make sure that the Category is indeed unique, otherwise you'll get the error.
Bob
Sorry about the confusion.
That's the bit I was hoping for some help with:
Coudl you share that snippet of code?
That's the bit I was hoping for some help with:
You need to put the check at the beginning of the Form HTML to see if the user has already responded. I posted some very similar code in the last few days.
Coudl you share that snippet of code?
Hi srthomas,
Bob
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `#__some_table`
WHERE `cf_user_id` = '".$user->id."' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count ) {
echo "You've already completed this";
return;
}
?>Bob
Hi greyhead,
I've the same problem, but the field's name I need to make unique is "codice_fiscale"
I want that this field is unique and I want to avoid double inserts, so where should I put that code you posted? and how can I persionalize that code to my needs?
Thank u so much!
I've the same problem, but the field's name I need to make unique is "codice_fiscale"
I want that this field is unique and I want to avoid double inserts, so where should I put that code you posted? and how can I persionalize that code to my needs?
Thank u so much!
Hi angie_iu,
I think that the code you need is:
I think that the code you need is:
<?php
$codice_fiscale = JRequest::getString('codice_fiscale', '', 'post');
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `#__some_table`
WHERE `codice_fiscale` = '$codice_fiscale' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count ) {
echo "You've already completed this";
return;
}
?>
thank u...but where should i insert this code? on submit code (before sending), in extra code? where?
should I insert my table here?
sorry but I really don't know php code!
thanx
FROM `#__some_table`
should I insert my table here?
sorry but I really don't know php code!
thanx
Hi angie_iu,
You should probalby use this version (a small change in the message display) in the Serverside validation box on the form Validation tab:
You should probalby use this version (a small change in the message display) in the Serverside validation box on the form Validation tab:
<?php
$codice_fiscale = JRequest::getString('codice_fiscale', '', 'post');
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `#__some_table`
WHERE `codice_fiscale` = '$codice_fiscale' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count ) {
return "Questo codice fiscale è già stato inserito";
}
?>
This topic is locked and no more replies can be posted.
