Topic: Cancel Account page with feedback form before cancelation
Ok u need 2 files for this
lib.cancel.php put it inside /includes/lib/
crate it and add this code to it:
<?php
//------------------------------------------------
// Includes
//------------------------------------------------
include SYS_PATH . 'includes/languages/' . SYS_LANG . '/lang.lib.contactus.php';
include SYS_PATH . 'includes/core/core.email.php';
include SYS_PATH . 'includes/fns/fns.validate.php';
//------------------------------------------------
// Check if user has access to this page
//------------------------------------------------
if (!$PREFS->conf['enable_feedback'])
{
$TEMPLATE->set_message("error", ($LANG['core']['no_access']), 0, 0);
redirect(VIR_PATH . ($PREFS->conf['fancy_urls'] ? "account/home/" : "index.php?m=account_home"));
}
//------------------------------------------------
// Show contact form
//------------------------------------------------
show_contactus();
//------------------------------------------------
// Show contact form
//------------------------------------------------
function show_contactus()
{
global $DB, $LANG, $TEMPLATE, $SESSION, $PREFS;
//------------------------------------------------
// Set template file
//------------------------------------------------
$TEMPLATE->set_template("cancel.tpl");
//------------------------------------------------
// Assign page title
//------------------------------------------------
$TEMPLATE->assign("app_page", ($LANG['core']['menu_cancel']));
//------------------------------------------------
// Check if user has access to this page
//------------------------------------------------
if (!$SESSION->auth && !$SESSION->conf['can_send_feedback'])
{
$TEMPLATE->set_message("error", ($LANG['core']['not_loggedin']), 0, 0);
redirect(VIR_PATH . ($PREFS->conf['fancy_urls'] ? "account/login/" : "index.php?m=account_login"), 1);
}
//------------------------------------------------
// Get fields
//------------------------------------------------
$from = isset($_POST['from']) ? $DB->strip_slashes(trim($_POST['from'])) : '';
$subj = isset($_POST['subject']) ? $DB->strip_slashes(trim($_POST['subject'])) : '';
$body = isset($_POST['body']) ? $DB->strip_slashes(trim($_POST['body'])) : '';
$captcha = isset($_POST['captcha']) && $_POST['captcha'] ? $DB->strip_slashes(trim($_POST['captcha'])) : "";
//------------------------------------------------
// Check if the user has clicked on Submit
//------------------------------------------------
if (isset($_POST['iscancel']) && $_POST['iscancel']) {
if (send_feedback($from, $subj, $body, $captcha)) $body = "";
}
$_SESSION['captcha'] = random_string(5);
//------------------------------------------------
// Assign page title
//------------------------------------------------
$TEMPLATE->assign("from", htmlentities2utf8($from));
$TEMPLATE->assign("body", htmlentities2utf8($body));
$TEMPLATE->assign("subj", $subj);
return 1;
}
// End Function
//------------------------------------------------
// Send feedback
//------------------------------------------------
function send_feedback($from, $subj, $body, $captcha)
{
global $DB, $LANG, $TEMPLATE, $SESSION, $PREFS;
// *system demo admin label* //
//------------------------------------------------
// Validate email
//------------------------------------------------
$valid_email = validate_email($from);
if ($from == "")
{
$TEMPLATE->set_message("error", ($LANG['contactus']['empty_email']), 0, 0);
return 0;
}
elseif ($valid_email == 1)
{
$TEMPLATE->set_message("error", str_replace("%1%", 4, ($LANG['contactus']['email_too_long'])), 0, 0);
return 0;
}
elseif ($valid_email == 2)
{
$TEMPLATE->set_message("error", ($LANG['contactus']['invalid_email']), 0, 0);
return 0;
}
//------------------------------------------------
// Validate body
//------------------------------------------------
if ($body == "")
{
$TEMPLATE->set_message("error", ($LANG['contactus']['empty_body']), 0, 0);
return 0;
}
//------------------------------------------------
// Check if captcha is available and accepted
//------------------------------------------------
if ($PREFS->conf['feedback_captcha'] != 0 && strcasecmp($_SESSION['captcha'], $captcha) != 0 && extension_loaded('gd'))
{
//------------------------------------------------
// Set the message
//------------------------------------------------
$TEMPLATE->set_message("error", ($LANG['contactus']['invalid_catcha']), 0, 0);
return 0;
}
//------------------------------------------------
// Create email class
//------------------------------------------------
$EMAIL = new Email();
//------------------------------------------------
// Send out an email to the member
//------------------------------------------------
$EMAIL->send($from, $PREFS->conf['return_email_name'], $PREFS->conf['feedback_email'], $subj, $body."\n\nSender IP:".$SESSION->get_ip());
//------------------------------------------------
// Set message and redirect to the default page
//------------------------------------------------
redirect(VIR_PATH . ($PREFS->conf['fancy_urls'] ? "account/privacy/cancel/" : "index.php?m=account_privacy&p=cancel"));
return 1;
}
// End Function
?>create a file called
cancel.tpl and put it inside /temlplates/your template/
put this code in it:
<!-- INCLUDE header.tpl -->
<div class="header_wrap">
<div class="location_wrap">
<div class="location">
<h1>Account Cancelation Form</h1>
</div>
<div class="clear"></div>
</div>
<div class="options_wrap">
<div class="title">
<h1>Account Cancelation Form</h1>
</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
<!-- INCLUDE message.tpl -->
<!-- IF hide_content != "1" -->
<div class="outter page_contactus">
<div class="typepage">
<div class="dataitem single">
<div class="form">
<form name="edit" method="post" action="">
<div class="fieldset">
<dl class="fieldset">
<dt></dt>
<dd><input type="hidden" class="text" size="40" id="field_from" name="from" value="{session.email}" /></dd>
<dt><label for="field_subject">{lang:"contactus","subject"}</label></dt>
<dd><input type="text" class="text" size="40" id="subject" name="subject" value="Account Cancelation Form" /></dd>
<dt><label for="field_body">Why do you cancel your account and feedback.</label></dt>
<dd><textarea class="textarea textarea_full" id="field_body" name="body">{body}</textarea></dd>
<!-- IF settings.feedback_captcha -->
<dt><label for="field_captcha">{lang:"contactus","verify_number"}</label></dt>
<dd>
<input type="text" id="field_captcha" class="text captcha" name="captcha" maxlength="5" />
<img src="{virtual_path}includes/fns/fns.captcha.php" border="0" alt="" />
</dd>
<!-- ENDIF -->
<dd class="submit"><input class="submit" name="submit" value="{lang:"contactus","submit"}" type="submit" /></dd>
</dl>
</div>
<input type="hidden" name="iscancel" value="1" />
</form>
</div>
<div class="clear"></div>
</div>
</div>
<div class="clear"></div>
</div>
<!-- ENDIF -->
<!-- INCLUDE footer.tpl -->go to your language files:
/includes/languages/english/lang.core.php
add a line:
"menu_cancel" =>
"Cancel Account",
then open header.tpl file
and add this line where you want to show the cancel link in the menus
<li class="blocked">{anchor:url1="cancel/",url2="index.php?m=cancel",name="custom|cancel_account"}</li>after they access the page they will seea form to enter feedback and acptcha and after clicking submit tyhey wil be redirected to the cancel page and u get an email with the forms details