Submit a widget's form from outside the widget

Hello there,

I’ve got a big form which is needed in several screens. So I thought it would be a good idea to put it in a widget to reuse/maintain it easily.

The problem I have is that I don’t want to put the submit button of this form in the widget. The submit button is in a wizard (“Next>>” button) and if I put this inside the widget it’s not flexible (maybe I want a maintenance screen with a “Save” button and pass different GET parameter, or maybe I just want to put this button somewhere else on the screen).

The name of the widget’s form is details-form. I’ve tried something like this in the view that uses the widget:



    var formToSubmit = document.getElementById('details-form');

    jQuery.yii.submitForm(formToSubmit,'/website/client/registration',{});return false;}



and the button is

echo CHtml::button('Next >>', array('id' => 'yta', 'type' => 'submit'));

When I click the button the action is properly triggered but the POST variable is empty…

Any idea ? Am I in the right direction or is there a easier way to do it?



You could perhaps try ajaxSubmitButton ?

OK the only difference with the generated code and my code is the "this" parameter of jQuery.yii.submitForm:


'#yt5','click',function(){jQuery.yii.submitForm(this,'/website/client/registration',{});return false;});

If I use it like this the POST is set and it works but how do I know if the right form’s been posted? What if there are two forms on the screen? I guess everything is posted…


Standard javascript would be something like:


JQuery along these lines:


Just use the correct form name or id to submit the right form.