Example Of Htmlbutton

Try to design a button to redirect to a new page in a form. If you want to use submitButton, then it will check ajax validation first, which not allow you go to the new page. Then I changed to use htmlButton in the form, but there is no example code for htmlButton in the wiki, so share the code here in case you have same issue when you want redirect to a new page by click button.

Code is below:




<?php

Yii::app()->clientScript->registerScript('htmlbutton', "

$('#forgot-button').click(function(){

	alert('here!');

	window.location = '". $this->createUrl('/site/forgotPassword')."';    

});

");

?>


<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'login-form',

	'enableClientValidation'=>true,

	'clientOptions'=>array(

		'validateOnSubmit'=>true,

	),

)); ?>

....

	<div class="row buttons">

		<?php echo CHtml::submitButton('Login'); ?>&nbsp;&nbsp;&nbsp;

		<?php echo CHtml::htmlButton('Forgot Password?',array('id'=>'forgot-button')); ?>		

	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->




Make sure you created actionForgotPassword in siteController.php to avoid 404 error message.