Monday, April 30, 2012

Problems in making a page with "yes", "no" buttons and confirm dialog

I am trying to make a delete confirmation page with both "yes" and
"no" buttons, and a confirmation dialog box. The dialog is to confirm
the "yes" option. Here is the relevant code I have:
(in the ctp view file)
<?php echo $this->Form->create('User', array(
'onsubmit' => 'return confirm("Really delete this account?");')); ?>
...

<?php echo $this->Form->submit(__('Yes')); ?>
<?php echo $this->Form->submit(__('No'), array('name' => 'no')); ?>
<?php echo $this->Form->end();?>

(in the controller)
public function delete($id = null) {
if (isset($this->params['form']['no']))
$this->redirect(array('action' => 'index'));
else {
$this->User->id = $id;
if (!$this->User->exists())
throw new NotFoundException(__('Invalid user'));
$user = $this->User->Find('first', array('conditions' =>
array('User.id' => $id)));
$this->set('user', $user);
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->User->delete()) {
$this->Session->setFlash(__('User deleted'));
$this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('User was not deleted'));
$this->redirect(array('action' => 'index'));
}
else
$this->request->data = $this->User->read(null, $id);
}
}

The problems are as follows:
1. the confirm dialog / message appears when the "no" button is
clicked.
2. the check on params['form']['no'] does not seem to stop the delete
when "no" is clicked.
3. the "no" button appears underneath the "yes" button, instead of to
the right of it.

Thanks.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: