Yii CHtml :: button and POST request for controller

Is it possible to send a CHtml::button request to send to the controller

 <?php echo CHtml::button('Button Text', array('submit' => array('controller/action'))); ?> 

I want to replicate the functionality of CHtml::link and POST to the controller

 <?php echo CHtml::link('Delete',"#", array("submit"=>array('delete', 'id'=>$data->ID), 'confirm' => 'Are you sure?')); ?> 

EDIT:

Button DOES NOT submit form

+4
source share
1 answer

Try the following:

 echo CHtml::button('Delete', array( 'submit'=>array('controllername/actionname',array('id'=>$id)), 'confirm' => 'Are you sure?' // or you can use 'params'=>array('id'=>$id) ) ); 

As you will see, button also uses the special htmlOptions clientChange attribute.

Refresh Explain submit , from doc link ():

submit: string, indicates the URL to submit. If the current element has a parent form, this form will be submitted, and if "submit" is not empty, its value will replace the URL of the form. If there is no parent form, the data listed in "params" will be sent instead (via the POST method) to the URL in the "submit" or the currently requested URL if "submit" is empty. Please note that if the "csrf" parameter is true, the CSRF token will also be included in the parameters.

my accent

As you already mentioned that you want to click on the delete action, by default gii generated by actionDelete expects an id in the URL, so I passed the id in the url, ie submit option.

+11
source

All Articles