0

I'm using easyModal to create modal windows in my web. Saw that they have callback onClose and I want use php code on close is it possible, if yes How to do that? I want to unset some values from sessions (don't have much experience in javascript, jquery or ajax)

This is my code:

<div id="ebox">
    <?php
    echo $_SESSION['unameE'];
    echo $_SESSION['pwordE'];
    echo $_SESSION['emailE'];
    ?>
</div>

$(function() {
    $('#ebox').easyModal( {
        autoOpen:<?php echo $error; ?>
        onClose:???

    });
});

Or maybe there is another solution that unsets values from session after displaying it once?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Anat0m
  • 37
  • 6
  • as long as the js is in line within the php page then you should be able to but its not nice. Why don't you load a php page into the modal and do the code within that, but within as a function not recommended ect – Simon Davies Dec 30 '13 at 22:21
  • 1
    $.ajax({ url: 'script.php?argument=value&foo=bar' }); see: http://stackoverflow.com/questions/3548802/call-php-function-from-jquery – Jérôme Teisseire Dec 30 '13 at 22:39
  • look into AJAX/jQuery's $.post function. you can't straight-up mix JS and PHP, they are separate processes on the client and server-side, respectively. – HC_ Dec 30 '13 at 23:18

1 Answers1

0

on your script you should have :

onClose: function(){ 
   $("#ebox").html(' ') ; 
   $.post("remove-session.php"); 
}

and then on the page "remove-session.php" you can do all sort of stuff with your session:

<?php 
  unset($_SESSION['unameE']); 
  //... 
  //or even
  session_destroy(); 
?>
zerzer
  • 613
  • 2
  • 8
  • 20