我有一个表单,我正在验证使用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功能来生成服务器端错误。但接下来的事情是如何将错误作为参数传递?甚至在重定向的页面上触发错误。 –