Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » Newsletter-v0.1.1 unsubscribe not working.

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 4117 Views
  • Viv
    Avatar
    Community Member
    30 Posts

    Newsletter-v0.1.1 unsubscribe not working. Link to this post

    I have installed a fresh version of Silverstripe 2.3 along with the Newsletter-v0.1.1 module. I have been able to create newsletter mailing list and got the subscribe system to work. Any new subscribers appear correctly under the Mailing List group in the security tag and under the Mailing List in the Newsletter tab of the CMS.

    However, using the '/unsubscribe' url things start to go wrong. I am correctly taken to a request for my email to be input, then the checkbox for the mailing list that I am subscribed to comes up. Go through this bit and then it just goes to a blank page. Refreshing the CMS, I can see that I have not been unsubscribed.

    When using the '/unsubscribe/(email)/(groupID)' url, just goes to a blank page - no confirmation or error message. Again, I am not unsubscribed from the Mailing List when I check back in the CMS.

    It almost seems like some functions of the Unsubscribe.php file are being called but others are not (?!)

    Any help here would be much appreciated.

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: Newsletter-v0.1.1 unsubscribe not working. Link to this post

    Confirmed, I bumped into this as well...

    Nasty bug , since we have the newsletter module running in production ( I know , I know .. I'm bad.... it is only 0.1.1 ) ...

    Did you already create a ticket for this ?

    ADDENDUM :
    The unsubscribe link that gets send in the mail _does_ work properly for me , so for example :
    http://www.mysite.com/unsubscribe/index/emailaddress@tounsubscribe.com/4 does work.

    It is just the www.mysite.com/unsubscribe that does not work for me.

  • altima
    Avatar
    Community Member
    3 Posts

    Re: Newsletter-v0.1.1 unsubscribe not working. Link to this post

    Hey,

    i has just edited the code from the newsletter module, that the unsubscribe url can be used to remove the entered user!

    The problem what i've found is, the forms cut of the mailaddress in the header, so i just change it to the member id and edit the data functions. Here the changes from me:

    Unsubscribe.php

    function unsubscribe($data, $form) {

          $email = $this->urlParams['Email'];
    /***********************************************/
    //      Change to get Data by ID
    //      $member = DataObject::get_one( 'Member', "Email = '{$email}'" );
          $member = DataObject::get_by_id( 'Member', $email );
    /***********************************************/

          if(!$member){
    /***********************************************/
    //      Change to get Data by ID
    //    $member = DataObject::get('Member', "`EmailAddress` = '$email'");
       $member = DataObject::get_by_id('Member', $email);
    /***********************************************/
    }

    if( $data['MailingLists'] ) {
    foreach( array_keys( $data['MailingLists'] ) as $listID ){
          
          $nlType = DataObject::get_by_id( 'NewsletterType', $listID );
          $nlTypeTitles[]= $nlType->Title;
    $this->unsubscribeFromList( $member, DataObject::get_by_id( 'NewsletterType', $listID ) );
    }

    $sORp = (sizeof($nlTypeTitles)>1)?"newsletters ":"newsletter ";
    //means single or plural
    $nlTypeTitles = $sORp.implode(", ", $nlTypeTitles);
        $url = "unsubscribe/done/".$member->Email."/".$nlTypeTitles;
            Director::redirect($url);
    } else {
        $form->addErrorMessage('MailingLists', _t('Unsubscribe.NOMLSELECTED', 'You need to select at least one mailing list to unsubscribe from.'), 'bad');
       Director::redirectBack();
    }
    }

    ...

    class Unsubscribe_MailingListForm extends Form {

       protected $memberEmail;

       /****Create an ID-Environment variable****************/
       protected $memberID;
       /***********************************************/

       function __construct( $controller, $name, $member, $email ) {

       if($member) {
          $this->memberEmail = $member->Email;

          /*****Load the Member.ID to the variable**************/
          $this->memberID = $member->ID;
          /***********************************************/
       }

    $fields = new FieldSet();
    $actions = new FieldSet();

    if($member) {
        // get all the mailing lists for this user
        $lists = $this->getMailingLists( $member );
    } else {
       $lists = false;
    }

    if( $lists ) {
        $fields->push( new LabelField('SubscribedToLabel', _t('Unsubscribe.SUBSCRIBEDTO', 'You are subscribed to the following lists:')) );

    foreach( $lists as $list ) {
    $fields->push( new CheckboxField( "MailingLists[{$list->ID}]", $list->Title ) );
    }

    $actions->push( new FormAction('unsubscribe', _t('Unsubscribe.UNSUBSCRIBE', 'Unsubscribe') ) );
    } else {
        $fields->push( new LabelField('NotSubscribedToLabel',sprintf(_t('Unsubscribe.NOTSUBSCRIBED', 'I\'m sorry, but %s doesn\'t appear to be in any of our mailing lists.'), $email) ) );
    }

    parent::__construct( $controller, $name, $fields, $actions );
    }

    function FormAction() {
          /**** Change the FormAction Button to submit the ID******/
          //return $this->controller->RelativeLink() . "index/{$this->memberEmail}?executeForm=" . $this->name;
          return $this->controller->RelativeLink() . "unsubscribe/{$this->memberID}/";
          /***********************************************/
    }

    protected function getMailingLists( $member ) {
    // get all the newsletter types that the member is subscribed to
    return DataObject::get( 'NewsletterType', "`MemberID`='{$member->ID}'", null, "LEFT JOIN `Group_Members` USING(`GroupID`)" );
    }
    }

    i hope this is helpful to use the newsletter module completly.

    greets Enno

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: Newsletter-v0.1.1 unsubscribe not working. Link to this post

    using the code above, i got the following error once i check off which newsletters i want to unsubscribe from:

    Missing argument 2 for Unsubscribe_Controller::unsubscribe(),
    function unsubscribe($data, $form) {
    $email = $this->urlParams['Email'];
    /***********************************************/
    // Change to get Data by ID
    // $member = DataObject::get_one( 'Member', "Email = '{$email}'" );
    $member = DataObject::get_by_id( 'Member', $email );
    /***********************************************/


    I'm sure there's a better way to do this, but i got around it by modifying the unsubscribe function as follows:

    function unsubscribe($data, $form = null) {


    I'm not sure what the best way to fix this problem is though. any thoughts?
    -Chris

  • Big Bang Creative
    Avatar
    Community Member
    92 Posts

    Re: Newsletter-v0.1.1 unsubscribe not working. Link to this post

    Did anyone fix this? I have the same problem, the link just eventually submits to a blank page and nothing happens.

  • Gravitational FX
    Avatar
    Community Member
    22 Posts

    Re: Newsletter-v0.1.1 unsubscribe not working. Link to this post

    Hi there.

    If you've got a spare couple of minutes, could you fun through how to install the newsletter module under SS2 .3.0
    I'm very new to SS and cannot get this newsletter module to run.

    There seems to be a newsletterv0.1.1 and also a tar which extracts to "modules\newsletter..."

    Don't really know which files to add where.

    Thanks,

  • Chris Rae
    Avatar
    Community Member
    17 Posts

    Re: Newsletter-v0.1.1 unsubscribe not working. Link to this post

    I've just finished fixing the unsubscribe bug in the Newsletter module. It's not pretty, but then neither is the Newsletter module.

    All you should need do is replace the 'Unsubscribe.php' file that comes as part of the newsletter module in the /code folder with this one.

    I've only tested this using SS 2.3.3 but there's no funny business going on so it should be sweet with other versions.

    http://dl.dropbox.com/u/805663/Unsubscribe.php

  • Roelfsche
    Avatar
    25 Posts

    Re: Newsletter-v0.1.1 unsubscribe not working. Link to this post

    Thank you Chris,
    I actually started debugging but with your code it works now.
    There is still a typo left in translation:
    I think in line 178 it should be

        $fields->push( new LabelField('SubscribedToLabel', _t('Unsubscribe.SUBSCRIBEDTO', 'You are subscribed to the following lists:')) );


    instead of

        $fields->push( new LabelField('SubscribedToLabel', _t('Unsubcribe.SUBSCRIBEDTO', 'You are subscribed to the following lists:')) );


    Anyway, the functionality works also without that ;-)
    Roelfsche

    4117 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.