Afterfind & Beforesave

Hi all

I have a form where users enter their email and it signs them up to a newsletter. Users can unsubscribe via a link, what I want is to re-subscribe users should they enter their email again in the form.

The Email attribute is unique. So I made a afterFind function like this


 public function afterFind(){

	if(parent::afterFind()){

	 $this->oldAttributes = $this->attributes;

	 if ( $this->oldAttributes['Email'] == $this->Email)

	 if ($this->MemberStatus == 0)

	 $this->MemberStatus == 1;

         // $this->save(false); tried this but unsuccessful (unsurprisingly)

    return true;

	}else { 

    return false; 

	}

}

Here’s the issue, as Email is unique the model will not save the afterFind changes if the Email exists (So I beleive, ), it won’t even try execute the beforeSave method. It will return the message ‘Email already exists’.

My questions are how can I work around this so it saves, and can I change the output message if the user re-subscribes?

Thanks

I have one idea in your subscription table save the email and set subscribed=1 (i assumed that subscribed is a column that identify whether the user is subscribed or not) this means that user is subscribed. and if the user want to unsubscribe just update subscribed=0 and when the user want to subscribe again instead of saving the same email you can just update the subscribed=1