刷新页面时如何停止发送表单

刷新页面时如何停止发送表单

问题描述:

All says add these codes (header(..); exit();)

We have: site.com/index.php?r=controller/index, some form and fields with names "filters[...]" We submited form and then after refreshing the page form is getting sent again.

added in index.php:

if ( isset($_POST['filters']) ) {
    header("Location: site.com/index.php?r=controller/index");
    exit;
}

added in controller:

unset($_POST);

What is going wrong?

所有人都说添加这些代码( header(..); exit(); code>) p>

我们有: site.com/index.php?r=controller/index code>,一些名称为“ filters [...]的表单和字段 ] code>“我们提交表单然后刷新页面表单后再次发送。 p>

在index.php中添加: p>

  if(isset($ _ POST ['filters'])){
 header(“Location:site.com/index.php?r=controller/index");
 exit; 
} 
  在控制器中添加了代码>  pre> 
 
 

: p>

  unset($ _ POST); 
  code>  pre> 
 \  n 

出了什么问题? p> div>

You can use redirect() or refresh() function after save/validate data:

if($model->save()){
    $this->redirect('site/login');
}else{
    $this->render('index',[...]);
}

or

if($model->save()){
    $this->refresh();
}else{
    $this->render('index',[...]);
}