I have a form, and I would like to ask confirmation when the page is closed by the user before submit the values. I already tried the script described in this question but it seems not to work: the userSubmitted value figure like always true, and the pop-up doesn't appear.
The code in my template is:
<script>
window.onbeforeunload = function() {
if(!userSubmitted)
return 'Are you sure that you want to leave this page?';};
</script>
the code in my controller is:
$userSubmitted=false;
//...
$form->handleRequest($request);
if ($form->isValid()) {
$userSubmitted=true;
//...
return $this->render('DefaultBundle::formupload.html.twig', array(
'form' => $form->createView(), 'userSubmitted->$userSubmitted
));
//...