PHP Classes

Confirmation Popup?

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  How to Show Google Ma...  >  All threads  >  Confirmation Popup?  >  (Un) Subscribe thread alerts  
Subject:Confirmation Popup?
Summary:How can I create a confirmation pop up window.
Messages:3
Author:Jonathan Bramwell
Date:2007-03-29 21:29:43
Update:2007-03-30 15:43:40
 

  1. Confirmation Popup?   Reply   Report abuse  
Picture of Jonathan Bramwell 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>

  2. Re: Confirmation Popup?   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-03-30 05:50:22 - In reply to message 1 from Jonathan Bramwell
What happens is that the form is being submitted right after you attempt to redirect, so it does not redirect in time.

What you need to do is to return false to prevent form submission. Your ONSUBMITTING value should be "confirmation(this); return false;"

  3. Re: Confirmation Popup?   Reply   Report abuse  
Picture of Jonathan Bramwell Jonathan Bramwell - 2007-03-30 15:43:40 - In reply to message 2 from Manuel Lemos
Thanks for the quick response. It worked perfectly.

Jonathan