我有一個表單,我正在驗證使用CFWheels模型驗證和表單助手。CFWheels:在redirectto而不是渲染頁面上顯示錶單錯誤
我的索引()動作/視圖在控制器代碼:
public function index()
{
title = "Home";
forms = model("forms");
allforms = model("forms").findAll(order="id ASC");
}
#startFormTag(controller="form", action="init_form")#
<select class="form-control">
<option value="">Please select Form</option>
<cfloop query="allforms">
<option value="#allforms.id#">#allforms.name#</option>
</cfloop>
</select>
<input type="text" name="forms[name]" value="#forms.name#">
#errorMessageOn(objectName="forms", property="name")#
<button type="submit">Submit</button>
#endFormTag()#
這種形式提交給init_form()動作和代碼是:
public function init_form()
{
title = "Home";
forms = get_forms(params.forms);
if(isPost())
{
if(forms.hasErrors())
{
// don't want to retype allforms here ! but index page needs it
allforms = model(tables.forms).findAll(order="id ASC");
renderPage(action="index");
//redirectTo(action="index");
}
}
}
你可以從看上面的代碼我驗證表單字段的值,如果有任何錯誤發送到原始索引頁面。我的問題是,因爲我正在渲染頁面,所以我還必須重新輸入頁面所需的其他變量,例如在這種情況下的「allforms」下拉菜單。
有沒有辦法不輸入這樣的變量?如果不是renderPage()我使用redirectTo(),那麼錯誤不顯示?這是爲什麼?
爲了清楚起見,我想將頁面發送/重定向到原始窗體並顯示錯誤消息,但我不想輸入呈現該頁面所需的其他變量?有沒有辦法。
如果您需要更多說明,請讓我知道。
你爲什麼不車輪的閃光信息功能顯示錯誤信息 –
如何傳遞我在模型中定義的自動生成錯誤?如果我使用flash,那麼我必須編寫自己的驗證代碼並傳遞我自己的驗證消息。我想使用CFWheels功能來生成服務器端錯誤。但接下來的事情是如何將錯誤作爲參數傳遞?甚至在重定向的頁面上觸發錯誤。 –