Reputation: 147
I made a login logout form and i have the posibility if i want to delete my account . If i press the button Sterge cont
a popout window wil apear and ask me if i really want to delete this account. If i hit NU
the account will not be deleted and the window will close but if i hit DA
the account will be deleted.
The problem which i want to resolve is that if i hit DA
the window will do the php delete account part and after that will close and redirect my page profil.php
to index.php?accountdeleted
This is how it looks the user profile.
This is how it looks the pop up window.
Upvotes: 1
Views: 1441
Reputation: 7948
You can just bind the closing of popup event. You can do something like this:
profil.php
<button type="button" id="delete" onclick="window.open('your_popup.php', 'popup', 'height=400, width=400, top=0, left=0,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no')">Delete</button>
Then on the your_popup.php
:
<?php
if(isset($_POST['confirm_delete'])) {
// do you query or database delete, etc.
// at the end
echo '<script type="text/javascript">self.close(); opener.location.href = "http://localhost/citate_celebre/profil.php";</script>';
}
?>
<form method="POST" action="popup.php">
<button type="button" id="cancel_delete">Cancel</button>
<button type="submit" name="confirm_delete">Delete</button>
</form>
Upvotes: 1
Reputation: 1
Make sure that you had the window instance of popup.
var popupWindow = window.open(...) //Open the popup
popupWindow.onbeforeunload = function(e) {
window.location.href = 'index.php?accountdeleted'; //redirect to new page
};
Upvotes: 0