Difference between #25 and #29 of
By Example: CHtml

Revision #29 has been created by resurtm on Aug 11, 2011, 8:37:16 AM with the memo:

generating dropdownlists with optgroup
« previous (#25) next (#30) »

Changes

Title unchanged

By Example: CHtml

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

listData, chtml, link, button

Content changed

[...]
***

**Example 9: Linking to a controller action via POST with confirmation dialog**

Delete actions created using gii require the delete request be sent via POST to help prevent deleting objects by accident. Below is an example how to create a link that sends the request via POST and also asks for confirmation. Where you are redirected after the delete depends on your delete action.

 
 
```php 
<?php echo CHtml::link('Delete',"#", array("submit"=>array('delete', 'id'=>$data->ID), 'confirm' => 'Are you sure?')); ?
Note that the `id` link parameter below is a GET type parameter (submit URL will be something like `http://example.com/post/delete/id/100`).
 
 
```php 
<?php echo CHtml::link('Delete',"#", array("submit"=>array('delete', 'id'=>$data->ID), 'confirm' => 'Are you sure?')); ?>
 
```
 
If you are using CSRF protection in your application do not forget to add csrf parameter to the htmlOptions array.
 
 
```php 
<?php echo CHtml::link('Delete',"#", array("submit"=>array('delete', 'id'=>$data->ID), 'confirm' => 'Are you sure?', 'csrf'=>true)); ?>
 
```
 
 
***
 
 
**Example 10: Linking to a controller action via POST with POST parameters**
 
 
If you need to make POST request with arbitary link with additional POST parameters you should use following code (submit URL will be something like `http://example.com/blog/deletePost/param/100`).
 
 
 
```php 
<p><?php echo lnk('Delete blog post', '#', array(
 
'submit'=>array('blog/deletePost', 'param'=>100),
 
'params'=>array('id'=>$post->id, 'status'=>Post::STATUS_DELETED_BY_OWNER),
 
'csrf'=>true,
 
)); ?></p
>
```
[...]
```

**
Example 5:* You cand find CHtml class at `yii/framework/web/helpers/CHtml.php`.

## Links

[Russian Version dropDownList()](http://dbhelp.ru/by-example-chtml-dropdownlist/page/)
[Russian Version listData()](http://dbhelp.ru/by-example-chtml-listdata/page/)
[...]
79 0
74 followers
Viewed: 993 826 times
Version: 1.1
Category: Tutorials
Written by: jonah
Last updated by: glicious
Created on: Sep 25, 2009
Last updated: 8 years ago
Update Article

Revisions

View all history