How does button 'submit' URL work?

I am working to learn a pre-existing Yii app. In one form, there is a button coded like this:

echo CHtml::button(‘Go Back’, array(‘submit’ => array(‘controllerName/actionName’, ‘id’ => $model->id)));

(Where controllerName and actionName are of course, specific to my installation.)

Note that this is not an official HTML form Submit button. For that you, of course, use CHtml::submitButton(). The term ‘submit’ is a special value, described in the docs for CHtml::clientChange(), so that’s no mystery. I see how this is supposed to behave. But…

Using the debugger in my browser (Safari), the raw HTML generated by the echo command is this:

<input name="yt1" type="button" value="Go Back" id="yt1">

So how, when I click the button, is the appropriate action taken? I.e. where in the Yii framework is the submit array stored and associated with the button? Looks like "magic" to me, but then Yii is full of that… ;-b

And while I’m at it, where do the name and id in the raw HTML come from?

Andrew

Hi.

Yii don’t generate only HTML tags but also JavaScript code.

Look at the last few lines of HTML source code, you’ll find a event handler of the button like this:




jQuery('body').undelegate('#yt0','click').delegate('#yt0','click',function(){jQuery.yii.submitForm(this,'/yiiProject/controller/action/id',{});return false;});



Thank you, that makes things much clearer!