I'm currently making a newsletter that let users subscribe and unsubscribe. Subscribing is a success but not on unsubscribing. can you help me out guys, here's my codes...
Controller
class AddsController extends AppController {
public $helpers = array('Html','Form','Session','Flash');
public $components=array('Session');
public function index() {
if($this->request->is('post')) //posting to db
{
$this->Add->create();
$this->Add->save($this->request->data);
$this->Flash->set('The user has been saved.', array('element' => 'success'));
return $this->redirect('index'); //redirects to index.ctp
}
}
/*public function delete($email = null) {
if($this->request->is('post')) {
$this->Add->exists($email) {
$this->Add->delete($email);
$this->Session->Flash('Unsubscribed');
return $this->redirect('index');
}
}
function delete(){ //delete html
$email = $this->request->data['email'];
if($this->Add->exists($email)){
$this->Add->delete($email);
$this->Session->Flash('Unsubscribed');
//$this->Flash->set('Unsubscribed', array('element' => 'danger'));
return $this->redirect('index');
}
} */
function delete() {
$email = $this->request->data['email'];
if($this->Add->exists($email)){
$this->Add->delete($email);
$this->Session->Flash('Unsubscribed');
//$this->Flash->set('Unsubscribed', array('element' => 'danger'));
return $this->redirect('index');
}
}
}
View
<?php echo "<section>";
echo $this->Form->create('Add'); //<form > 'modelname'
echo "<label>E-mail:</label>";
echo $this->Form->input('email',array('label'=>false , 'placeholder'=>'your email')); //email input
echo $this->Form->submit('Subscribe'); //subscrib button
echo $this->Form->end();//</form>
echo "</section>";
echo "<section>";
echo $this->Form->delete('Add',array('action'=>'delete')); //<form >
echo "<label>E-mail:</label>";
echo $this->Form->input('email',array('label'=>false , 'placeholder'=>'your email')); //email input
echo $this->Form->submit('Unsubscribe',array('action'=>'index'),array('style'=>'background:red'));
echo $this->Form->end();//</form>
echo "</section>";
My view is just "entering data into db and deleting existed data out the db Model
<?php
App::uses('AppModel' , 'Model');
class Add extends AppModel
{
public $name = "Add";
public $useTable = 'request';
public $primaryket = 'id';
public $useDbConfig = 'default';
}
db tablename: request; Just the delete row Thank you in advance!!!