Romed7442
Romed7442

Reputation: 149

Yii - CHtml::link() Post with Confirmation Dialog Doesn't work

echo CHtml::link('Delete', '#', array('submit'=>'admin/page/exhibitions/delete', 'params'=>array('test'=>50), 'csrf'=>false, 'confirm'=>'Are you sure?' ));

I can see in the inspector that Yii has inserted these line of code in html

jQuery(function($) {
  jQuery('body').on('click','#yt0',function(){if(confirm('gdfgdfgdfgd')) {jQuery.yii.submitForm(this,'admin/page/exhibitions/delete',{'test':50});return false;} else return false;});
  jQuery('body').on('click','#yt1',function(){if(confirm('gdfgdfgdfgd')) {jQuery.yii.submitForm(this,'admin/page/exhibitions/delete',{'test':50});return false;} else return false;});
  jQuery('body').on('click','#yt2',function(){if(confirm('gdfgdfgdfgd')) {jQuery.yii.submitForm(this,'admin/page/exhibitions/delete',{'test':50});return false;} else return false;});
});

However, when I click on the generated link, the confirmation box pop up, when I click ok, nothing happened, except that my console shows the following error:

Uncaught TypeError: Cannot call method 'submitForm' of undefined

Anyone got an idea?

Upvotes: 0

Views: 2213

Answers (2)

Enes Genc
Enes Genc

Reputation: 196

If you have another jquery at end of the document the jquery.yii.js will be overriden. Remove another jquery instances.

Upvotes: 0

BaBL86
BaBL86

Reputation: 2622

Check, do you use CForm, CActiveForm, or TBActiveForm widget? Because of submit is an a part of form component and must be wrapped with

<form ...></form>

and other parameters.

If you want only link - don't use Submit parameter.

CHtml::link(
    'Delete',
    array('admin/page/exhibitions/delete','test'=>50),
    array('confirm' => 'Are you sure?')
);

Upvotes: 3

Related Questions