Insertion duplicates record

cenzomita 26 May, 2015
Hi, sometimes when I insert a new record Chronoform inserts twice record.
This problem does not always occur, it seems that the records are duplicated random.
GreyHead 27 May, 2015
Hi cenzomita,

Very unlikely that this is random - there will be some pattern.

Is it possible that the user is clicking Submit more than once?

Bob
cenzomita 27 May, 2015
Hi,
I don't think that the problem is the multiple submit, otherwise the cases would be few.
GreyHead 27 May, 2015
Hi cenzomita,

Please drag a Debugger action into the On Submit event, then submit the form and post the debug - including the 'dummy emails' results here.

Note: if you are using the Easy Wizard you can turn on Debug on the Others tab in CFv4 or the Setup tab in CFv5.

Bob
cenzomita 28 Jul, 2015
Hi Bob, excuse me if I don't reply but the problem seemed to occur more. Unfortunately I found duplicated records.
In my form I have a not-editable field code automatically generated with a timestamp using the following JS code
function loadNumBolla() {
  var d;
  if (!Date.now) {
    d = Date().getTime();
  } else {
    d = Date.now();
  }
  d = d / 1000 | 0;
  $('numero_bolla').value = d;
}

I noticed that in database there are two records with the same code but the creation date ("created" field on database table) different, 1 hour of difference. How it it possible?
This condition should exclude the multiple click on submit button.
The value of "created" field of db when is calculated?
GreyHead 29 Jul, 2015
Hi cenzomita,

Unless you have an entry in $form->data['created'] then the 'created' date+time is set when the database query runs i.e. when the record is saved.

Bob
cenzomita 29 Jul, 2015
Ok, then you agreed with me that it is not possible that the records are created at the same time.
It is difficult for user create two records with the same "numero_bolla" (created with timestamp) and creation field very different.
Do you have an ideas about problem?
GreyHead 30 Jul, 2015
Hi cenzomita,

Sorry, I have no good ideas at all. Are they exactly one hour apart - in which case it might??? be something to do with time-zones?

Bob
cenzomita 30 Jul, 2015
The difference between their data creation is not exactly 1 hour, but substantially the problem is that it is not possible to have two records with the same timestamp generated.
I don't understand where is the problem. I have think also that the records are duplicated for a reason and queued for database insertion, but 1 hour is too much.
GreyHead 30 Jul, 2015
Hi cenzomita,

I doubt that any database delay is more than a second or two. The cause of this is somewhere else.

Bob
cenzomita 26 Oct, 2015
Hi Bob,
the problem above is not resolved, but from some days it is aggravated.
When I insert a new record Chronoform inserts multiple records (something 7-8 records).
GreyHead 26 Oct, 2015
Hi cenzomita,

These are all with the same time-stamp or at different times?

There is nothing that I know of in ChronoForms that will create duplicated records at different times.

Bob
cenzomita 26 Oct, 2015
Yes Bob, all records have the same time-stamp.
The records have a field (a code) which value is calculated by timestamp, these values are the same for all duplicated records. Then, these records have the "created field" with the same date but different time, you can see the attachment.
[attachment=0]scrshot.png[/attachment]
cenzomita 26 Oct, 2015
The following attachment shows the "numero_bolla" field that contains the time-stamp in millisecond
[attachment=0]scrshot.png[/attachment]
GreyHead 27 Oct, 2015
Hi cenzomita,

Your 'numero_bolla' is created once when the form is submitted; the 'created' value is set when the MySQL query runs.

I can only guess that there is a loop somewhere and the DB Save is being re-run . . . I have no idea where though.

Bob
cenzomita 27 Oct, 2015
Hi Bob,
I don't find any loop. Then I don't think in a loop cause because this multiple insertion does not occur always.
Where should I check?
cenzomita 27 Oct, 2015
In setup tab I have the following codes:
on onload I inserted a "load javascript" with the following code to enable all field before submit
window.addEvent('domready', function()
{
  ...

  $('chronoform-spedizione_insert').addEvent('submit',enabler);
}
);

function enabler()
{
  var inputs = document.getElementsByTagName('input');
  for (i=0; i<inputs.length; i++){
        inputs[i].disabled='';
  }
}

on onsubmit I inserted custom code to format data fields
<?php
$user = JFactory::getUser();
$form->data['cliente'] = $user->name;
$form->data['data_bolla'] = date('d-m-Y');

if (strlen($form->data['note_cliente']) > 0)
{
   $form->data['note_presenti'] = "X";
}

if (strlen($form->data['data_ritiro']) > 0)
{
   $form->data["data_ritiro_convert"]  = date("Y-m-d", strtotime($form->data["data_ritiro"]));
}
?>

event switcher to send mail in particular conditions
<?php
if (array_key_exists("priorita", $form->data) && $form->data["priorita"] =="Urgente"){
return "success";
}else{
return "fail";
}
?>

a final custom code to print page
<?php
$doc = JFactory::getDocument();
$script = "
jQuery(document).ready(function(jQ){
  function printPage()
  {
    var html, css, csss_file, printWin;
    css = \"\";
    css = \"<style type='text/css'>\"+css+\"</style>\";
    css_url = '';
    if ( css_url !== '' ) {
        css_url = \"<link rel='stylesheet' type='text/css' href='\"+css_url+\"' media='print' />\";
    }
    html = '<html><head>'+css+css_url+'</head>'+jQ(id).html()+'</html>';

    printWin = window.open('', '', 'left=100, top=100, width=600, height=400, toolbar=0, scrollbars=0, status=0' );
    printWin.document.write(html);
    printWin.document.close();
    printWin.focus();
    printWin.print();
    printWin.close();
  }
  var id;
  id = '#print_div';
  jQ('#print_button').css('visibility', 'visible');
  jQ('#print_button').click(printPage);
});
";
$doc->addScriptDeclaration($script);
?>

Can you see problems?
GreyHead 27 Oct, 2015
Hi cenzomita,

Sorry but I don;'t have any suggestions about where to check. I haven't seen this reported before so I think it is most likely something about the way you have the form or site set up.

The code you posted looks OK - I don't see anything there that will cause a problem unless there is a submit button in the page you are using to print?

Bob
cenzomita 27 Oct, 2015
When the user click on submit button the application execute the form submit, after the compilated form is automatically printed by the last code written in previous post.
If you wont I can give you the credential of my web site.
cenzomita 02 Nov, 2015
No other suggestions for me?
My application is in pre-production, the users have inserted many data and waiting for production. I don't know if an update resolve the problem, or if I can have other problems.
Please, help me!
GreyHead 02 Nov, 2015
Hi cenzomita,

I am pretty clear that this is a problem with the way you have the form set up, or possibly with your custom code so a ChronoForms upgrade is not going to help. By all means PM me the site URL, the form name, and a SuperAdmin login and I'll take a quick look - but I may not see the problem there.

Bob
GreyHead 02 Nov, 2015
Hi cenzomita,

I can’t work out what the form is supposed to do? Is it an Edit from from the CC listing? If so I can’t get any values to show in the CC listing to check that.

You appear to have both a CC Application linked to an Edit action which will save the record as well as a DB Save which will save the record.

I would expect the CC Application action to return the user to the listing so I'm not clear how the Print code works after that.

Bob
cenzomita 02 Nov, 2015
The edit form (xxx_edit and xxx_edit_cliente) only have a link to CC with integrated save action.
The insert form (xxx_insert) has a DB save action, after a link to CC to show the list of items inserted after the save and the custom code for printing (it opens a new window that containt the compiled form that user can print).

Unfortunately it is a bit complex but I hope it is clear now.
cenzomita 26 Jan, 2016
Hi Bob, after several months the problem still exists.
Is there a solution? Could I resolve it if I update to last version of component?
Can I lost the customization with update?
GreyHead 27 Jan, 2016
Hi cenzomita,

I still don't have any suggestions except that you debug what is happening step by step to see if you can pin down exactly where the loop is happening.

Yes, please do upgrade CF and CC to the latest versions - but I don't think that will make any difference. There is something in the way you have this combination set up that is causing the duplication.

Bob
This topic is locked and no more replies can be posted.