![Picture of Jonathan Bramwell Picture of Jonathan Bramwell](/graphics/unknown.gif)
Jonathan Bramwell - 2007-03-29 21:29:43
Hi
I want to submit a form, validate it and then confirm that I want to proceed before saving the submitted form data to a file on the server side.
I have created a short java script function that produces the confirmation window and call it by setting the $form->ONSUBMITTING="confirmation(this)" property of the form.
This runs OK and I get a confirmation form and the alert('dosave'). However the location does not change to the dosave.php. I tested the javescript stand alone switching to www.google.com and that works OK. I tried setting the location to www.google.com" instead of dosave.php as a test but it still just shows my form again. I also tried only Capturing output if $doit is 0, but this still does no change page or show my orignal page as it thinks $doit is now set and it is not unset until I exit the browser, since WasSubmitted always returns "doit"
It may be that changing page is the wrong thing todo. Any suggestions on how I could make this work?
I have attached some of the code below.
Thanks
Jonathan
***********************************************************
On the server side I use the WasSubmitted function.
$form->LoadInputValues($form->WasSubmitted('doit'));
$verify=array();
if($form->WasSubmitted('doit')){ // submitted...
if(($error_message=$form->Validate($verify))=='')
{
$doit=1;
}else
{
$doit=0;
$error_message = HtmlEntities($error_message);
}
}else
{
$error_message="";
$doit=0;
//
}
if (!$doit){
if(strlen($error_message))
{
/*
* If there is at least one field with invalid values, get the name of the
* first field in error to make it get the input focus when the page is
* loaded.
*/
Reset($verify);
$focus=Key($verify);
}
else
{
/*
* Make the email field get the input focus when the page is loaded
* if there was no previous validation error.
*/
$focus='name';
}
/*
* Connect the form to the field to get the input focus when the page
* loads.
*/
$form->ConnectFormToInput($focus, 'ONLOAD', 'Focus', array());
}
$onload=HtmlSpecialChars($form->PageLoad());
********************************************************
This is the javascript function.
<script type="text/javascript">
<!--
function confirmation(theform) {
var answer = confirm("Are you sure you want to save this configuration?\n Once saved the system will reboot.")
if (answer){
alert('dosave')
window.location = "../dosave.php";
}
else{
alert('cancelled')
}
}
-->
</script>