How To Enable Csrf In Certain Forms Only

Hi All,

I want to ask how i enable csrf in certain forms only not paths?

Why do you want to disable it for any forms? Can you explain your scenario?

I have a website which i have convert it from codeigniter to yii, and now want to enable csrf but the problem that i have to do this step by step because forms i add csrf as urgent some else are not urgent.

Adding CSRF protection is simply a matter of opening each form with CHtml::beginForm() and closing it with CHtml::endForm(). The second isn’t actually required but is probably good for consistency. How many forms do you have?

There’s no built in way to activate CSRF for specific forms as far as I’m aware.

I can see why you might want to disable CSRF on some controllers.

I had the same problem when interfacing with Worldpay on one project. I got a posted callback to verify the transaction, but with global CSRF, obviously this failed with no token.

There is a thread here that seems to have a solution, although I haven’t tried it myself.

http://www.yiiframework.com/forum/index.php/topic/14173-disable-csrf-token-validation-for-certain-paths/

Thanks, solved.