How to create an unsubscribe page in magento - magento

I would like to create a direct unsubscribe page in magento, I found this instruction to follow but the steps 1 and 2 are not clear As I'm not a professional.
Can someone please help me clarify these two steps. Where to create the "unsubscribe.phtml" page? How to add the just created block in it?
Thank you in advance.
1. Create a phtml page say “unsubscribe.phtml” containing the code to create the unsubscribe form.
<?php $newsletterObj = new Mage_Newsletter_Block_Subscribe(); ?>
<div class="newsletter-unsubscribe">
<div class="newsletter-unsubscribe-title"><?php echo $this->__('Submit your email id to unsubscribe newsletter') ?></div>
<form action="<?php echo $newsletterObj->getUnsubscribeFormActionUrl() ?>” method="post" id="newsletter-validate-detail">
<div class="block-content">
<div class="input-box">
<input type="text" name="email" id="newsletter" title="<?php echo $this->__('Sign up for our newsletter') ?>” class="input-text required-entry validate-email” value="<?php echo $this->__('Enter Your Email Here') ?>” onfocus="if(this.value==’<?php echo $this->__('Enter Your Email Here') ?>’)this.value=’’;” onblur="if(this.value==’’)this.value=’<?php echo $this->__('Enter Your Email Here') ?>’;”
/>
</div>
<div class="actions">
<button type="submit" title="<?php echo $this->__('Submit') ?>” class="button"><span><span><?php echo $this->__('Submit') ?></span></span></button>
</div>
</div>
</form>
<script type="text/javascript\">
//<![CDATA[
var newsletterSubscriberFormDetail = new VarienForm(’newsletter-validate-detail’);
//]]>
</script>
</div>
2) Create a CMS page. Add the just created block in it. So that your CMS page will contain that form.
3) Now in page \app\design\frontend\base\default\template\newsletter\subscribe.phtml add the code to add a link of the cms page.
<div class="unsubscribe">
<?php echo $this->__('Unsubscribe') ?>
</div>
4) In page \app\code\core\Mage\Newsletter\Block\Subscribe.php add a function to create the form action url which is called in the “unsubscribe.phtml”.
public function getUnsubscribeFormActionUrl()
{
return $this->getUrl(’newsletter/subscriber/unsubscribecus’, array(’_secure’ => true));
}
5) Now in \app\code\core\Mage\Newsletter\controllers\SubscriberController.php page add new action for unsubscribe process.
/**
* Unsubscribe newsletter from frontend
*/
public function unsubscribecusAction()
{
$email = $this->getRequest()->getParam(’email’);
$subsModel = Mage::getModel(’newsletter/subscriber’);
$subscriber = $subsModel->loadByEmail($email);
$id = (int) $subsModel->getId();
$code = (string) $subsModel->getCode();
if ($id && $code) {
$session = Mage::getSingleton(’core/session’);
try {
Mage::getModel(’newsletter/subscriber’)->load($id)
->setCheckCode($code)
->unsubscribe();
$session->addSuccess($this->__(’You have been unsubscribed.’));
}
catch (Mage_Core_Exception $e) {
$session->addException($e, $e->getMessage());
}
catch (Exception $e) {
$session->addException($e, $this->__(’There was a problem with the un-subscription.’));
}
}
$this->_redirectReferer();
}

Since a can't leave a comment and this question isn't marked as solved yet, i'll assume you still need an answer.
I would suggest placing the unsubscribe.phtml file in /template/newsletter/
For step 2 you can use this code
{{block type="core/template" template="newsletter/unsubscribe.phtml"}}
so the page will contain your form.
If you already figured out how to do this, please post an answer to your own question further on.

Would it be an idea to add an unsubscribe button next to the subscribe button (or allow for a variable in the block call that sets it to yes/no display) - this way you capture both

Related

(Codeigniter) Ion Auth CSRF Error:This form post did not pass our security checks (when loading views)

I'm using Ion Auth authentication library in Codeigniter. When I load my footer view, I get an CSRF Error(This form post did not pass our security checks). When I remove the footer view, it works fine though! Is there anything I'm doing wrong here? Thanks!
function edit_user($id) {
//I'm only posting the last part of the code of edit_user function in the auth controller
$this->load->view('layout/header');
$this->_render_page('auth/edit_user', $this->data);
$this->load->view('layout/footer'); // I'm getting an error when I load this footer view.
}
This is the code in my views.
<h1><?php echo lang('edit_user_heading');?></h1>
<p><?php echo lang('edit_user_subheading');?></p>
<div id="infoMessage"><?php echo $message;?></div>
<?php echo form_open(uri_string());?>
<p>
<?php echo lang('edit_user_fname_label', 'first_name');?> <br />
<?php echo form_input($first_name);?>
</p>
<p>
<?php echo lang('edit_user_lname_label', 'last_name');?> <br />
<?php echo form_input($last_name);?>
</p>
<p>
<?php echo lang('edit_user_company_label', 'company');?> <br />
<?php echo form_input($company);?>
</p>
<p>
<?php echo lang('edit_user_phone_label', 'phone');?> <br />
<?php echo form_input($phone);?>
</p>
<p>
<?php echo lang('edit_user_password_label', 'password');?> <br />
<?php echo form_input($password);?>
</p>
<p>
<?php echo lang('edit_user_password_confirm_label', 'password_confirm');?><br />
<?php echo form_input($password_confirm);?>
</p>
<h3><?php echo lang('edit_user_groups_heading');?></h3>
<?php foreach ($groups as $group):?>
<label class="checkbox">
<?php
$gID=$group['id'];
$checked = null;
$item = null;
foreach($currentGroups as $grp) {
if ($gID == $grp->id) {
$checked= ' checked="checked"';
break;
}
}
?>
<input type="checkbox" name="groups[]" value="<?php echo $group['id'];?>"<?php echo $checked;?>>
<?php echo $group['name'];?>
</label>
<?php endforeach?>
<?php echo form_hidden('id', $user->id);?>
<?php echo form_hidden($csrf); ?>
<p><?php echo form_submit('submit', lang('edit_user_submit_btn'));?></p>
<?php echo form_close();?>
Ion auth csrf protection is older. CI-2 already have
This is provide to security when posting form, ex: POST is from local or server?
ion auth controller file, you see like codes below:
// do we have a valid request?
if ($this->_valid_csrf_nonce() === FALSE)
{
show_error($this->lang->line('error_csrf'));
}
If you remove these validation, you will not get csrf error
You can enable security with CI core lib
http://ellislab.com/codeigniter/user-guide/libraries/security.html
$config['csrf_protection'] = TRUE;
You have to use form_open() tag to triggger csrf protection.
Same problem happened to me when i was trying to add common/header and common/footer to the auth/reset_password page.
Issue was that I was using relative paths for the JS included in the footer part. After a lot of experiment using the base_url() fixed the issue.
I have the sale pb but a replace flashdata by userdata, it's just a little less secure but it's a good solution.

How to pass variable between views? Codeigniter

Codeigniter noob here:
I am wanting to let users click a button inside someone's profile in order to send them a message, I need to pass the variable from the view back to the controller and into another view, how can I accomplish this? The variable is $username in the first view:
View #1: (this works)
<a href="<?php echo base_url().'user/user_message';?>">
<button type="submit" class="btn btn-info btn-small" title="Send Message" >Send Message</button>
</a>
<h3><?php echo $username;?>- Public Profile</h3>
Controller:
public function user_message($username)
{
if($this->form_validation->run() == FALSE)
{
$this->load->view('header_loggedin');
$this->load->view('user/send_message', $username);
$this->load->view('footer');
}
else
I basically want to grab the $username variable from my first view and make it avaliable in the user/send_message view. Thanks for your help!
Change the following line
<a href="<?php echo base_url().'user/user_message';?>">
To
<?php echo base_url().'user/user_message/'.$username;?>
So, your public function user_message($username){ ... } will receive the $username as it's parameter. Once you get it in your controller method then you can send it to the second view when you load the view with other data, like for example,
...
$data['username'] = $username;
$this->load->view('viewname', $data);
Then you can use $username in your view.
Why not pass hidden field and post it to your controller. Try this.
VIEW
<a href="<?php echo base_url().'user/user_message';?>">
<button type="submit" class="btn btn-info btn-small" title="Send Message" >Send
Message</button>
</a>
<input type="hidden" name="username" value="<?php echo $username; ?>"/>
CONTROLLER
public function user_message()
{
$username = $this->input->post('username');
if($this->form_validation->run() == FALSE)
{
$this->load->view('header_loggedin');
$this->load->view('user/send_message', $username);
$this->load->view('footer');
}

magento: onepagecheckout, stuck on billing information

Magento: onepagecheckout, stuck on billing information
This is the response we got:
When I look # the code in http://baleinen.com/checkout/onepage/ I cannot find an block called shipping-method.
Any ideas howto fix? (and this is the Sentana template, I almost cant imagine that this hasnt worked before)
{"goto_section":"shipping_method","update_section":{"name":"shipping-method","html":" <dl class=\"sp-methods\">
<dt>Betaal en verzendkosten (PostNL)<\/dt>
<dd>
<ul>
<li>
<span class=\"no-display\"><input name=\"shipping_method\" type=\"radio\" value=\"flatrate_flatrate\" id=\"s_method_flatrate_flatrate\" checked=\"checked\" \/><\/span>
<label for=\"s_method_flatrate_flatrate\">NL <span class=\"price\">\u20ac\u00a01,25<\/span> <\/label>
<\/li>
<\/ul>
<\/dd>
<\/dl>
<script type=\"text\/javascript\">
\/\/<![CDATA[
var shippingCodePrice = {'flatrate_flatrate':1.25};
$$('input[type=\"radio\"][name=\"shipping_method\"]').each(function(el){
Event.observe(el, 'click', function(){
if (el.checked == true) {
var getShippingCode = el.getValue();
var newPrice = shippingCodePrice[getShippingCode];
if (!lastPrice) {
lastPrice = newPrice;
quoteBaseGrandTotal += newPrice;
}
if (newPrice != lastPrice) {
quoteBaseGrandTotal += (newPrice-lastPrice);
lastPrice = newPrice;
}
checkQuoteBaseGrandTotal = quoteBaseGrandTotal;
return false;
}
});
});
\/\/]]>
<\/script>
"},"allow_sections":["shipping"],"duplicateBillingInfo":"true"}
http://baleinen.com/checkout/onepage/
I had a similar issue with OnePage Checkout not completing.
I had to make the following change:
app/design/frontend/base/default/template/checkout/onepage/payment.phtml
Find the folowing section:
<form action="" id="co-payment-form">
<fieldset>
<?php echo $this->getChildHtml('methods') ?>
</fieldset>
</form>
and add an id to the fieldset element:
<form action="" id="co-payment-form">
<fieldset id="checkout-payment-method-load">
<?php echo $this->getChildHtml('methods') ?>
</fieldset>
</form>
Now my checkout proceeds OK.
Problem was that Magento JS was trying to find col-right, when there was none.
This is col-left and reported as a small defect because it i hardcoded in JS

phpBB sessions do not carry from page to page

I have a website (located in the root directory) with a forum located in ./forum/
I have successfully integrated phpBB's sessions into the index of my website using the following codes:
In my index page before <html>:
<?php include_once("include/phpbb.php");
// check for logout request
$cp = $_GET['cp'];
// is it a logout? then kill the session!
if ($cp == "logout") {
$user->session_kill();
$user->session_begin();
echo "Successfully Logged Out.";
}
?>
phpbb.php:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>
Displaying the information - this is in header.php which is included in my index:
<?php
// Page login notice
if ($user->data['user_id'] == ANONYMOUS)
{
?>
<img src="forum/images/avatars/gallery/noavatar.png" style="float:left; width:72px; height:72px;">
<div class="login">
<form method="POST" action="forum/ucp.php?mode=login">
<ul><li><span>Username:</span> <input class="loginfield" type="text" name="username" size="20"></li>
<li><span>Password:</span> <input class="loginfield" type="password" name="password" size="20"></li>
<li>Remember Me? <input type="checkbox" name="autologin"> Register</li>
<li><input type="submit" value="Login" name="login"></li>
</ul>
<input type="hidden" name="redirect" value="../index2.php">
</form>
</div>
<?php
} else { ?>
<img src="forum/images/avatars/gallery/<?php echo $user->data['user_avatar']; ?>" style="float:left; width:72px; height:72px;">
<div class="login">
Welcome back, <?php echo $user->data['username_clean']; ?><br>
You have <?php echo $user->data['user_unread_privmsg']; ?> new messages<br>
Log Out
</div>
<?php } ?>
I can successfully log in on the index using the form I created, but if I then click to another page (i.e. about.php) I am asked to log in again. This happens for every page. This also happens if I click over to the phpbb forum.
Is there any way to make it so I can log in on any page, and not have the session restart when browsing other pages?
Thank you for any help!
Check the cookie path in your board configuration in the phpBB ACP. phpBB by default tries to create restrictive cookies with the board root specified as the cookie path.
If the cookie path is /forum/, sessions won't persist in /.

Embed wordpress registration into homepage

I am trying to embed the wordpress registration into the homepage. I already created a custom register page, the problem is that it is calling to the header information and I get this error, when I include it with php include.
Warning: Cannot modify header information - headers already sent
Is there a way I can use my code but alter it somehow/work with it somehow, so that the registration form is fully embedded/works in the page using ajax, but that it works. I am not brilliant with Php so please excuse if this is a silly question:
Current register code(works in its own page but not when included in the homepage template)
<?php
require_once(ABSPATH . WPINC . '/registration.php');
global $wpdb, $user_ID;
//Check whether the user is already logged in
if (!$user_ID) {
if($_POST){
//We shall SQL escape all inputs
$username = $wpdb->escape($_POST['username']);
if(empty($username)) {
echo "User name should not be empty.";
exit();
}
$email = $wpdb->escape($_POST['email']);
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", $email)) {
echo "Please enter a valid email.";
exit();
}
$random_password = wp_generate_password( 12, false );
$status = wp_create_user( $username, $random_password, $email );
if ( is_wp_error($status) )
echo "Username already exists. Please try another one.";
else {
$from = get_option('admin_email');
$headers = 'From: '.$from . "\r\n";
$subject = "Registration successful";
$msg = "Registration successful.\nYour login details\nUsername: $username\nPassword: $random_password";
wp_mail( $email, $subject, $msg, $headers );
echo "Please check your email for login details.";
}
exit();
} else {
echo "";
?>
<!-- <script src="http://code.jquery.com/jquery-1.4.4.js"></script> --> <!-- Remove the comments if you are not using jQuery already in your theme -->
<?php
if(get_option('users_can_register')) { //Check whether user registration is enabled by the administrator
?>
<h1><?php the_title(); ?></h1>
<br /><br />
<div id="result"></div> <!-- To hold validation results -->
<form id="wp_signup_form" action="" method="post">
<label><p>Username:</p></label>
<input type="text" name="username" class="text" value="" />
<br /><br />
<label><p>Email address:</p></label>
<input type="text" name="email" class="text" value="" /> <br />
<br />
<input type="submit" id="submitbtn" class="Buttons" name="submit" value="Register" />
<br />
<br />
</form>
<script type="text/javascript">
$("#submitbtn").click(function() {
$('#result').html('<img src="<?php bloginfo('template_url'); ?>/images/loader.gif" class="loader" />').fadeIn();
var input_data = $('#wp_signup_form').serialize();
$.ajax({
type: "POST",
url: "<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>",
data: input_data,
success: function(msg){
$('.loader').remove();
$('<div>').html(msg).appendTo('div#result').hide().fadeIn('slow');
}
});
return false;
});
</script>
<?php
}
else echo "Registration is currently disabled. Please try again later.";
?>
</div>
</div>
<?php
echo "";
} //end of if($_post)
}
else {
wp_redirect( home_url() ); exit;
}
?>
is not safe to use a custom method for registration and mailing.
so i suggest to look at this http://digwp.com/2010/12/login-register-password-code/
i hope that's what you want.
best regard.
As webfan suggests, it isn't a good idea to reproduce the registration functionality on the homepage. Much better would be to simply cut and paste the login form from the registration page and keep the form action pointed to the registration page:
<form method="post" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>">
<!-- registration form HTML goes here -->
</form>

Resources