link a specific Controller action to submit button

Hi,

I am new to yii, and I try to avoid using the default action indexAction() when the user submits the search form. I created a searchAction() to handle the search logic but i don’t know how to call it after the user clicks the submit button.

Any help?

thanks in advance.

Ilias

Did you code it from scratch? well you could try changing the “action” attribute of your form. :)

I wanted that after submitting the form

<?php echo CHtml::beginForm(); ?>

form fields 

<?php echo CHtml::endForm(); ?>

I can call actionSearch() function of the SiteController.php.

how can I change the action attribute of the form to call the actionSearch() function?

Thanks in advance.

The first parameter of CHtml::beginForm is the form’s action. You need to pass the uri you want to post to as that, either as a static string or using the createUrl() functionality.


CHtml::beginForm( $this->createUrl( 'search' ) );

Say_Ten is correct. In addition, you may want to make the method as “get” since you don’t actually post to the database.


CHtml::beginForm($this->createUrl('search'), 'get');

please see the documentation for more information about the function :)

it works! Thanks Say_Ten & levz :)

All the best! ;)