views:

199

answers:

1

I created a confirmation page for deleting an item. This works perfectly.

Now I want to appear the confirmation page in fancybox, still passing all the variables and delete the data or close the dialog.

It's important that the process still works as it does now (delete->confirmationpage->redirect/deletion) so that users with javascript disabled can perform these actions without a problem.

Now have I been reading about zend framework,ajax, json and more, but the more I read, the less I understand.

So in a nutshell, my question:

I want to pass a variable to the fancybox and if 'yes' perform the delete action or on 'no' close the dialog. This within the zend framework and jquery.

Any advice or tips are greatly appreciated!

+1  A: 

You need to use content switching in your ajax which will then render your action appropriately, for example:

function confirmDeleteAction() {
  if($this->_request->isXmlHttpRequest()) {
    //This is ajax so we want to disable the layout
    $this->_helper->layout->disableLayout();
    //Think about whether you want to use a different view here using: viewRenderer('yourview')
  }
  //The normal code can go here
}

function deleteAction() {
  //You probably don't want to show anything here, just do the delete logic and redirect therefore you don't need to worry where it's coming from
}

And in your fancybox, have a view that has a form and two buttons, the form should point to your delete action with the id of whatever your deleting as a get param. Set some javascript up that says something like (and this is mootools code, but you can convert it easily):

$('confirmButton').addEvent('click', function(e) {
   e.preventDefault();
   this.getParent('form').submit();
}
$('cancelButton').addEvent('click', function(e) {
   e.preventDefault();
   $('fancyBox').destroy(); //I'm not sure it has an id of fancyBox, never used it
}
Ashley