I want to have a button, that logs out the user on click. But I don't feel like creating a form for that, or making an "onclick" handler. Is there another way to do it?
<p class='loginposition normal'>
."$_SESSION['email']".<form action='/logout.php' method='post'><input class='logout-submit button' type='submit' style='float:right;' id='logoutbtn' value='Log Out'></form>
</p>";
I want them to be in one raw: user@user.com [Log Out]
If you want a POST request then you need either Ajax (which would be a silly technique to use for logging out) or a form.
Since logging out is not a repeatable action, POST is the correct tool to do it.
Get over your feelings and use a form.
You can deal with the twin problems of your HTML being invalid and additional line breaks by putting the paragraph inside the form instead of the other way around.
No, you have to use either forms or Javascript.
what about this (you have to edit your logout.php): ?
<a href="logout.php">Log Out</a>
<input class='logout-submit button' type='button' style='float:right;' id='logoutbtn' value='Log Out' onClick='window.location.href="./logout.php"'>
the shortest way if you want to use a button i think.
you could use ajax method of jQuery, something like this
$('#logout-button').click(function(){
$.ajax({
type: "POST",
url: "logout.php",
success: function() {
alert("You have been successfully logged out");
window.location.href = "home.php";
},
error: function() {
alert("Error! Something unexpected happened");
}
});
return false;
});
I guess that would work...
...you could use a flash buttons which sends a POST request to logput.php if u're familiar with as3 / as2