CHtml imageButton() and ClientChange()

Hi, I am using CHtml::imageButton() to display an up arrow to allow the user to vote. I have this working fine, it displays an arrow image with alt text and title text.

How do I link this button to an action in my controller?

On a side note, I tried using CHtml::clientChange() in the image button but I get an error:


Fatal error: Call to protected method CHtml::clientChange() from context 'CBaseController' in C:\xampp\htdocs\test\protected\views\site\index.php on line 24

Can someone explain how I should use clientChange - I don’t really understand.

You can specify clientChange as an item in htmlOptions (the key is clientChange of course, the value must be an array).

hi pestaa,

I’m having an error:




htmlspecialchars() expects parameter 1 to be string, array given


#0 Z:\WORK\xampp\htdocs\yii-1.0.9\framework\web\helpers\CHtml.php(71): htmlspecialchars()

#1 Z:\WORK\xampp\htdocs\yii-1.0.9\framework\web\helpers\CHtml.php(1810): encode()

#2 Z:\WORK\xampp\htdocs\yii-1.0.9\framework\web\helpers\CHtml.php(113): renderAttributes()

#3 Z:\WORK\xampp\htdocs\yii-1.0.9\framework\web\helpers\CHtml.php(385): tag()

#4 Z:\WORK\xampp\htdocs\yii-automoto\protected\components\views\userLoginHeader.php(30): button()

#5 Z:\WORK\xampp\htdocs\yii-1.0.9\framework\web\CBaseController.php(123): require()

...



trying to put a button using:




<?= Html::button('Register', array('clientChange', array('submit', 'users/create'))); ?>



it’s correct this? I understood of your previous answer the parameter for clientChange should be an array but I get an error in htmlspecialchars complaining just that

Thx!!

Hwangar

Ok, my own answer…

after looking into the code (and correcting my mistake of putting ‘submit’, ‘users/create’ instead of ‘submit’ => ‘users/create’ :P ), the correct way to set a button redirecting to an url is:




<?= Html::button('Register', array('submit' => 'users/create')); ?>



Thx!!!

Hwangar

Could you tell me what HTML was generated by this CHtml:Button ?

(Building Yii By Example)

The code




<?php echo CHtml::button('Test', array('submit' => 'site/index')); ?>



generates (first button on page)




<input name="yt0" type="button" value="Test" id="yt0" />



and also




<script type="text/javascript">

/*<![CDATA[*/

jQuery(document).ready(function() {

jQuery('#yt0').click(function(){jQuery.yii.submitForm(this,'site/index',{});return false;});

});

/*]]>*/

</script>



/Tommy

What if i dont want to submit? If i want to exec another JS function when a dropdown changes?

At least this is one way to do it (return false from beforeSend):




<?php

  echo CHtml::dropDownList(UserId,'',

    CHtml::listData(User::model()->lookupUser(),'UserId','Username'),

    array(

      'ajax'=>array(

        'beforeSend' => 'function(){alert("beforeSend event.");return false;}',

      )

    )

  );

?>



/Tommy