0
我有一個showSuccess頁面需要一些獲取變量,並在該頁面上是一個窗體。當表單提交到executeCreate()並且出現錯誤時,它會調用函數setTemplate('show')並返回到showSuccess。但是,get變量缺失。調用setTemplate()後顯示獲取變量
如何保持url不變?
我有一個showSuccess頁面需要一些獲取變量,並在該頁面上是一個窗體。當表單提交到executeCreate()並且出現錯誤時,它會調用函數setTemplate('show')並返回到showSuccess。但是,get變量缺失。調用setTemplate()後顯示獲取變量
如何保持url不變?
你可以從sfWebRequest
對象的GET變量 - 像下面應該工作):
public function executeCreate(sfWebRequest $request)
{
$getVars = $request->getGetParameters();
$qryString = http_build_query($getVars);
// ...some form creation and binding
if (!$form->isValid())
{
$this->redirect("module/show?" . $qryString);
}
}
你可能還需要這些在模板的形式。使用上面的代碼的相關部分在你的表演動作,將其設置爲視圖,就像任何其他變量和表單操作參數使用它們:
<form method="post" action="<?php echo url_for("module/create?" . $qryString); ?>">
</form>
雖然這正確遵守我的網址,通過使用重定向方法,它會丟失無效的表單,所以在這種情況下輸入的值和錯誤信息將丟失 – LTME 2010-05-25 19:48:25
,將if結構更改爲if($ form-> isValid()){...} '如果表格成功則重定向。這樣,如果驗證失敗,您的操作仍然會顯示錶單值等。讓我知道你是否想要一個例子:-) – richsage 2010-05-26 08:15:27