I want to use a confirmation popup to delete my items, so this is my delete action :
public function deleteAction()
{
$id = (int) $this->params()->fromRoute('id', 0);
$article = $this->getObjectManager()->find('\Application\Entity\Article', $id);
if ($this->zfcUserAuthentication()->hasIdentity()) {
if ($this->request->isPost())
{
$this->getObjectManager()->remove($article);
$this->getObjectManager()->flush();
return $this->redirect()->toRoute('blog');
}
}
else
{
return $this->redirect()->toRoute('user');
}
return new ViewModel(array('article' => $article));
}
and this is my blog view where i have the delete link :
<a href="<?php echo $this->url('delete', array('action'=>'delete', 'id' => $articles->getId())) ?>" class="btn btn-default btn-lg" onclick="if (confirm('Are you sure?')) { document.location = this.href; } return false;" id="dialog">Delete Article</a>
<?php endif;?>
<script type="text/javascript">
$(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Are you sure": function() {
document.form.submit();
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
</script>
the problem is when i press the link it's redirected to the delete.phtml view, what i want is to delete the item when i confirm the popup.
So please if someone has any solution i will be very appreciative :)
You could use
confirm
method.If you want to use jQuery UI dialog,
i know this an old question but it has help me. so i figure there must be others also looking for the answer. so here how i do it..
go to http://adriancallaghan.co.uk/jquery-confirmation-box-thickbox/
download and save the javascript into your 'js' folder (mine i put in 'js/azza/deletebox.js')
then add link to the file in your view *.phtml file
then edit your href as follows
very important to set both 'id' and 'class' as "dialog-confirm" to trigger the javascript function
and you also need Jquery, and Jquery-UI for this script to work
that's it...