ajax submit questions

I am trying to setup a form with buttons only. The form should only submit via POST. While trying out some of the sweet CHtml options for this purpose I noticed some strange behaviours.

1.When setup my post submission via CHtml::linkButton(); all works well until I disabled javascript. Does linkButton uses jquery to push a POST submit?

2.When trying to use either CHtml::ajaxButton() or CHtml::ajaxSubmitButton() my form failed when javascript is disabled. Is there an option or parameter that can set these nice buttons to work as a regular submission if js is disabled?

It would be great if anyone helps me answer the above two questions.

cheers,

b

  1. Yes it does.

  2. Can’t say that i know for sure, but I presume not. They are clearly ajax helpers, which mean they are designed to use ajax. And that’s a JS thing in this case.

Thanks rAWTAZ,

I have another question related to ajax submit and it is when I declare:

CHtml::ajaxSubmitButton() and according to the documentation I can include a 4th parameter array $htmlOptions=array ( ). In the html options I can declare ‘params’ but those parameters will be passed only when there is also ‘submit’=>‘url’ declared. If there is however a submit declared than the ajax is broken and Yii performs a regular POST submit. Is this the expected behavior as it does not make much sense to work that way. I would like to perform ajax request and still be able to pass params.

Cheers,

b

Hi

if you use ajaxSubmitButton, then you just need a form, where are some fields. And yii will take care the rest.

but if you use ajaxButton ,then you have to define these params in the ajax options like this:




    echo CHtml::ajaxButton('ajaxButtonName',

             CController::createUrl('controller/action'), // action which will handle the ajax

                array (

                        'type' =>'POST',

                        'update' => '#updatingHTMLelement', //if you want to update something in the view

                        'data' => array('id'=>'$var_id', 'var1'=>$var1), 

                ),

                array(

                             'class' => 'class1',

                             'title' => 'ajaxButton',

                             'id' => 'ajaxButton',

                ),

        );



and you can use much more ajaxoptions, all you have to do >> look it up on the jQuery API >> ajax properties

Thanks JMC!

I am experiencing some other issues with ajax submit process. I am trying to develop a feedback form as a separate widget. I have a radiobutton list with ajax[yes, no]. So if the person clicks on yes ajax loads thank you for your feedback. If the person clicks on No ajax loads a text area and ajaxSubmitButton to submit the text area. The problem here is that clicking on the ajaxsubmitbutton submits the form as a regular post submission and never submits it via ajax. Why do you think is that.

Here is some code:

The ajaxsubmitbutton code:


echo CHtml::ajaxSubmitButton('Send feedback', CController::createUrl('site/feedback'), array(

                                    'type'=>'post',

                                    'update'=>'#feedback',

                                ),array(

                                    'type'=>'submit',

                                    'name' => 'vote1',

                                    'class'=>'sendfeedback',

                                ));

the above button is located in a view file and is called by a renderPartial in siteController in actionNo if the user has clicked on No radio button.

Here is actionFeedback code:


$this->renderPartial('_feedbackform', array('model'=>$model),false,true);

The whole widget is located in protected/components and extends CPortlet.

Any help would be appreciated

Cheers,

bettor

OK I think was able to debug this little further by moving the ajax button to the portlet and got the following error:

Class_name does not have a method named "getModule".

Class_name is the class of my portlet. So I guess it expects the form to be handled by a controller class. Can anyone advise how to handle this in a portlet?

RESOLVED

Hi, is it possible to update 2 elements? i want to fill 2 listboxes after the selection…