how to add logout button to form?

samoht 25 Jun, 2009
Hello again,

I was asked if I could add a logout button next to the save button on my cf form. However, since the <form> tag cannot be in the Form HTML I was not sure how to do this.

Any Ideas??

Thanks,
samoht 25 Jun, 2009
OK so taking a stab at is my self I added a logout submit
<input type="submit" name="submit" value="Logout" />

and then in the On Submit code added this little catch
<?php
if ( $_POST['submit'] == 'Logout') {
header ("Location: http://www.surgimap.com/index.php?option=com_user&task=logout");
exit;
}
?>


and this does log the user out. Only problem is that it takes the user to a blank page. I would like the user to be logged out and taken to the welcome.html page. But if I am already redirecting them ??

I also tried:
$mainframe->logout();

but that takes me to a blank screen?
samoht 25 Jun, 2009
Sorry for posting... I found the solution!

Just in-case any one else needs to know:

First, put the lougout input in the form HTML:
<input type="submit" name="submit" value="Logout" />


Then in the On Submit code add:
<?php
if ( $_POST['submit'] == 'Logout') {
global $mainframe;
//preform the logout action
$error = $mainframe->logout();
//create the redirect variable
$return = 'http://www.yoursite.com/welcome.html';

	if(!JError::isError($error)){
		if ($return) {
			//there is probably a cleaner way to do this but you get the idea.
			$return = 'http://www.yoursite.com/welcome.html';
		}
	}
exit;
}
?>


and then whatever url you give to the $return variable will be the redirection after the logout. This actually ended up being much simpler than I thought.

enjoy!
Max_admin 26 Jun, 2009
Glad you made it, thanks for posting the solution!🙂

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger