[Solved] back one page url

Hi All,

i want to ask about Yii::app()->request->urlReferrer

i make a cancel in form.php with this code :


<?php echo CHtml::submitButton('Cancel',array('submit'=>Yii::app()->user->returnUrl,'style'=>'font-size: 14px;font-weight: bold;')); ?>

if i go to create or update page and immediately click the back button is back to the previous page. But when i go to create or update page and i write something in the textfield and not save it but i click the cancel button it didn’t back to the previous page but stuck in create or update page.

ho to fix this?

Thanks

can anybody help me?

No, not really. :)

You are referring to a different thing than what you use, so how can you be helped ? :)

This is what I do:


            	<?php echo CHtml::Button('Cancel', array('submit' => CHttpRequest::getUrlReferrer())); ?>

The problem with you code is that Yii::app()->user->returnUrl is most likely not set.

Use my code instead. It works (most of the time). ;)

thanks for your help. but the problem is still remain.

i put your code in views\_form.php


 <?php echo CHtml::Button('Cancel', array('submit' => CHttpRequest::getUrlReferrer())); ?>

the problem show when i want to create a data, if the textfield need required and i not fill it with text it show error. then i click the cancel button and it not back to the previous page because it get the current url. i want it back to the page before i create. how to do this?

thanks

finally i solved this problem. i use javascript to back one page for my problem like this


echo CHtml::button('Back',array('onclick'=>'js:history.go(-1);returnFalse;','style'=>'font-size: 14px;font-weight: bold;')); 

hope this will help someone, who have same problem with me.

Something that is worth stressing about:


js:history.go(-1)

JavaScript (obviously) has to be supported and enabled on the user’s device for this to work. It think it should be possible to combine Jacmoe’s solution in #3 with the JavaScript one, so you at least have a fallback option if JavaScript is not available.


js:history.go(-1);

After validation this code not working, can help me the same.