Hi, Experts,
I am maintaining some of company's perl/javascript codes and having problems in understanding them. One piece of code is listed below:
By design, upon clicking "Submit" button, the hidden CGI variable is assigned with a value of a js variable 'listOfFields' and then passed into save.pl. In real world, 99% of time the code is executed as expected. However, once a while, the CGI variable 'fields' is blank and thus save.pl does not know what to do. The worse part is that we can never reproduce it in house. But we do see it happened multiple times on our live server when our clients are using it remotely.
When this error happens, I have made sure that '@fieldList' is NOT null which is verified by the logs. I also studied the source codes very very carefully to make sure that 'listOfFields' was not overwritten before saveData() is called. But I can NOT prove that through logs, simply because it is executed on the clients' sides.
I suspect this is due to somehow 'saveData()' did not submit document.aForm.fields.value as designed, so that the CGI variable 'fields' becomes blank. But why? How can this happen?
BTW, one might suggest not using 'saveData()' and directly passing $fieldsList into save.pl:
Well, the answer is that 'saveData()' actually does more than I listed here. For example, it also validates 'listOfFields', which is omitted in this thread.
I hope I have made myself clear and look forward to your help. Thanks.
I am maintaining some of company's perl/javascript codes and having problems in understanding them. One piece of code is listed below:
Code:
my $fieldsList = join(',',@fieldList);
$jsSetupCode = <<EO_SETUP_CODE;
var listOfFields = new Array($fieldsList);
function saveData() {
document.aForm.fields.value = listOfFields;
document.aForm.submit();
return(false);
}
EO_SETUP_CODE
print
header(),
start_html(-title => 'My Title',-script => $jsSetupCode),
start_form(-name=>'aForm',-action=>'save.pl'),
hidden(-name=>'fields',-value=>''),
submit(-value=>'Submit', -onClick=>'saveData(); return(false)'),
end_form(),
end_html();
By design, upon clicking "Submit" button, the hidden CGI variable is assigned with a value of a js variable 'listOfFields' and then passed into save.pl. In real world, 99% of time the code is executed as expected. However, once a while, the CGI variable 'fields' is blank and thus save.pl does not know what to do. The worse part is that we can never reproduce it in house. But we do see it happened multiple times on our live server when our clients are using it remotely.
When this error happens, I have made sure that '@fieldList' is NOT null which is verified by the logs. I also studied the source codes very very carefully to make sure that 'listOfFields' was not overwritten before saveData() is called. But I can NOT prove that through logs, simply because it is executed on the clients' sides.
I suspect this is due to somehow 'saveData()' did not submit document.aForm.fields.value as designed, so that the CGI variable 'fields' becomes blank. But why? How can this happen?
BTW, one might suggest not using 'saveData()' and directly passing $fieldsList into save.pl:
Code:
hidden(-name=>'fields',-value=>"$fieldsList"),
Well, the answer is that 'saveData()' actually does more than I listed here. For example, it also validates 'listOfFields', which is omitted in this thread.
I hope I have made myself clear and look forward to your help. Thanks.