CHtml::ajaxsubmitbutton with params?

Hi there,

Really hoping someone can help me out as I’ve messed about with this for hours and really haven’t got anywhere… I’m following the documentation to the letter and trying every posisble variation with no luck and now I’m going a little crazy… scoured the net and all possible forums but nothing explains quite what I’m doing wrong.

I have a simple form which is successfully submitting with CHtml::ajaxsubmitbutton:




echo CHtml::ajaxSubmitButton(

        ($model->isNewRecord ? 'Create' : 'Save'), 

        $actionUrl,

        array(

                'update'	=> "#$myContainer",

                'dataType'	=> 'html',

                'complete'	=> $updateStatusScript

        ),

        array()

);



This all gets sent to the Controller fine and I’m PHPFirebugging the resulting $_POST array out the other end.

So, after looking at the documentation I figured I could send some additional params using the htmlOptions array which is currently empty, so I did this:




echo CHtml::ajaxSubmitButton(

        ($model->isNewRecord ? 'Create' : 'Save'), 

        $actionUrl,

        array(

                'update'	=> "#$myContainer",

                'dataType'	=> 'html',

                'complete'	=> $updateStatusScript

        ),

        array(

                'submit'        => $actionUrl,

                'params'        => array(

                                            'hello'     => 'hi there',

                                            'oh'        => 'yes'

            )

        )

);



And all I get it jQuery.yii is undefined. The whole error being as follows:




jQuery('#yt0').live('click',function(){jQuery.yii.submitForm(this,'/index.php/workRequest/update/56',{'hello':'hi there','oh':'yes'});return false;jQuery.ajax({'dataType':'html','complete':function(request, status) {

var statusContainer = $("#ajaxNotification1");

statusContainer.html('Operation successful.');

},'type':'POST','url':'/index.php/workRequest/update/56','cache':false,'data':jQuery(this).parents("form").serialize(),'success':function(html){jQuery("#workRequestFormContainer").html(html)}});return false;});

jQuery('#yt1').live('click',function(){if(confirm('Are you sure you want to delete this item?')) {jQuery.yii.submitForm(this,'/index.php/workRequest/delete/56',{});return false;} else return false;});



So I don’t get it. It’s probably something really obvious - I’m new to Yii but loving it.

Any help would be greatly appreciated.

Thanks!

htmlOptions are just for the element, not the script associated with it.

think this will work.




echo CHtml::ajaxSubmitButton(

        ($model->isNewRecord ? 'Create' : 'Save'), 

        $actionUrl,

        array(

                'update'        => "#$myContainer",

                'dataType'      => 'html',

                'complete'      => $updateStatusScript,

                'data'          => array(

                        'hello'     => 'hi there',

                        'oh'        => 'yes'

                )

        ),

        array(

                'submit'        => $actionUrl

        )

);



Hi! Thanks so much for the reply. I did this but it only sends the data field value pairs and not the form also. For some reason I also have to comment out either the first $actionUrl or the ‘submit’ => $actionUrl in the htmlOptions array for it to go through at all. Any ideas how to make the params in the htmlOptions work, or indeed any other way to send params alongside a form?

Thanks again!

You can add them as a querystring to the url.




echo CHtml::ajaxSubmitButton(

        ($model->isNewRecord ? 'Create' : 'Save'), 

        $actionUrl . '?hello=hi%20there&oh=yes',

        array(

                'update'        => "#$myContainer",

                'dataType'      => 'html',

                'complete'      => $updateStatusScript

        ),

        array(

                'submit'        => $actionUrl

        )

);



Then use $_GET[‘hello’]

Thanks for your reply… this is a valid solution but the end game for this is to send many more than two pairs which would make the GET route not such a good one.

I just don’t get why the htmlOption > params isn’t working like it seems it should. It’s description in the documentation makes it sounds exactly what I’m after:

The full version of which I found here :My link

Any ideas or examples of how this should work?

Thanks!

Any ideas on this anyone?

Thanks

If i had more time would look into it, but another way to get the params in the post would be to use hidden inputs


<input type="hidden" name="myname" value="something here" />

A HA! I’d thought of this before but I’ve since been round the houses trying other different ways and now you’ve bought me back to this idea and I’ve realised I can do it this way! So thank you! I might seem kind of elementary but there slightly more to it than I’ve been explaining. Essentially I want to send values along with the form values but I need them to be dynamically pulled by javascript from a separate form. Anyway. Reasons are irrelevent. You’ve helped me. So thank you :)

hope this helps :)

http://stackoverflow.com/questions/6348581/yii-ajaxsubmitbutton-with-fields-validation