I’m developing a site where on first visit, the user will be asked to input an email and which city he/she lives. I loaded it using colorbox and iframe. Here is the code in main.php :
Yii::app()->clientScript->registerScript('',
"$('document').ready(
function()
{
$.fn.colorbox({href:'http://www.veevou.com/visitor/create',
iframe:true,'width':'365px', 'height':'510px', onClosed:function(){ location.reload(true); }});
}
)");
$colorbox = $this->widget('application.extensions.colorpowered.ColorBox');
$colorbox
->addInstance('.colorbox', array('maxHeight'=>'80%', 'maxWidth'=>'80%'));
So, you see, the colorbox will render the page create.php and after the form is submitted, the controller will save the data then redirect to index page.
This is the controller :
if(isset($_POST['Visitor']))
{
$model->attributes=$_POST['Visitor'];
// Register only if he / she is not registered as member nor visitor
if($model->save())
{
echo "<script>parent.$.fn.colorbox.close(); </script>";
$this->redirect(array('site/index'));
}
}
else
{
$this->render('form',compact('model'));
}
But it says “cannot modify headers already sent…” . How to close the colorbox ? I have tried to put the “parent.$.fn.colorbox.close(); ” before redirecting to another page but it didnt work. Where should i put the $.fn.colorbox.close() ? I have tried several methods in another post but none works for me. Thanks
your problem is this part.
You echo something on your screen and then you redirect, this is not possible. What you want to do is redirect without echoing anything. After that you need to make sure the colorbox does not open again.