Hello,
Adrian Paciu helped to this question for me in the RSForm!Pro support tickets area. I think the answer would be helpful to others, so I'm copying the thread to the public forum. The posts are arranged newest at the top, original question at the bottom. Some URL's and emails have been changed for privacy.
I'm using Joomla 3.4.3
The answer is, I needed to move my field's value computation from the field's "default value" box to the PHP script area "Script called on form process."
I set the field's DEFAULT value using this code:
//<code>
$db=JFactory::getDBO();
$db->setQuery("SELECT MAX( CAST( `FieldValue` AS UNSIGNED ) ) cnt FROM #__rsform_submission_values WHERE FieldName='Application ID' AND FormId=6");
$db->query();
$result=$db->loadResult();
return intval($result)+1;
//</code>
Then in the PHP script area "Script called on form process." I set the field's value AGAIN, with this code:
//<code>
$db = JFactory::getDBO();
$db->setQuery("SELECT MAX( CAST( `FieldValue` AS UNSIGNED ) ) FROM #__rsform_submission_values WHERE `FieldName`='Application ID' AND `FormId`=6");
$input = $db->loadResult();
if ($input) {
$_POST['form']['Application ID'] = intval($input) + 1;
}
//</code>
06/08/2015 10:24:49
Adrian Paciu wrote:
Hello Carol,
You can try a similar approach as presented in the following forum post (notice example near the end):
www.rsjoomla.com/forum/37-rsform-pro/219...bmissions.html#26175
Regards!
06/08/2015 00:04:11
Carol Mattsson wrote:
Hello RSForms Support,
My form has a hidden field to which I assign a unique number. The field name is "application ID" and we've been assigning this field a value that appears to be based on your helpful post on how to add a counter for submissions here:
www.rsjoomla.com/support/documentation/r...for-submissions.html
That was a couple of years ago. Now the folks who handle the form submittals are pointing out that too often, the form's assigned application ID is the same as that of a previously submitted form. I noticed that this happens after we "manually" remove a submitted form that we no longer need.
I modified the query in the code that computes the value for this hidden field (see code below). It does a BETTER job, as the query looks at all the Application ID field values, picks the maximum value, and adds 1 to it.
But in testing, I've found this isn't good enough: if I start a form submission and fill in values until the last page then pause; and then from another computer start another form submission and fill it out to completion and submit; then go back to the first form submission and submit it, BOTH form submissions get the same Application ID.
So I'm out of ideas and I hope you can help me. I'd LIKE the application ID's to be sequential, but if that's not possible, then perhaps at least increasing in value?
The particulars are:
<scrubbed for privacy>
field name: Application ID
This is the field's value (the new code I'm testing), set from the "edit field" button, in the "General" tab, in the box labeled "Default Value":
//<code>
$db=JFactory::getDBO();
$db->setQuery("SELECT MAX( CAST( `FieldValue` AS UNSIGNED ) ) cnt FROM #__rsform_submission_values WHERE FieldName='Application ID' AND FormId=6");
$db->query();
$result=$db->loadResult();
return intval($result)+1;
//</code>
Please let me know if you need more information.
Thanks in advance,
Carol Mattsson