Please help me explain 9 line of code in Yii_user extension

This is the function plugin for RegistrationController of Yii_user module (http://www.yiiframework.com/extension/yii-user/)


	public function actions()

	{

		return (isset($_POST['ajax']) && $_POST['ajax']==='registration-form')?array():array(

			'captcha'=>array(

				'class'=>'CCaptchaAction',

				'backColor'=>0xFFFFFF,

			),

		);

	}

I can understand most of the part, but couldn’t figure the following question:

why they want to attach the capatcha action when it’s not a ajax request, and don’t want to attach capatcha action when it’s an ajax request?

Thanks!

I think it’s because the captcha code may change after it’s validation.

It may remain the same for a few times, but it will change at last when you continue trying to be validated. So the author of Yii-user wants the captcha to be validated only one time at the last moment of the registration.

[EDIT]

Sorry, the description above was not correct.

The validation of the captcha is performed in every ajax call.

By default, the captcha will remain the same for 3 times and will be changed for the 4th time.

So the author doesn’t want the captcha to be changed in ajax actions.

why?

why you mention validation?

Oops! I was wrong. Not the validation, but the creation of capthca image in the ajax action.

About the captcha image duration, please see this article and the link to a reference in it.

http://www.yiiframework.com/forum/index.php?/topic/19208-caching-captchas

To sum up, by default the same captcha image will be repeated 3 times and will be changed to a new one for the 4th time.

And a long form like the registration will require more than 3 ajax actions before it is completed. And you will not like the captcha image to be changed while you are still filling the form.

Thanks!