简体   繁体   English

cakephp表单帮助程序错误

[英]cakephp form helper bug

I think I've found a bug in Cake's FormHelper class, but maybe I'm just not using the correct function, so hopefully somebody on here knows. 我想我在Cake的FormHelper类中发现了一个错误,但是也许我只是没有使用正确的函数,所以希望这里的人知道。 Here's the relevant code: 以下是相关代码:

<?php
    echo $this->Form->input('first_name', array('value' =>'First Name', 'label' => false));
?>

As you can see, I'm just outputting an input text field that has a default value of First Name. 如您所见,我只是输出一个默认值为“名字”的输入文本字段。 The issue I'm experiencing is that if the user does not provide a valid name, then the form does not preserve the value that the user tried to submit with, instead it just shows the default value again (First Name). 我遇到的问题是,如果用户未提供有效名称,则表单不会保留用户尝试提交的值,而是仅再次显示默认值(名字)。 So basically, if I were to enter into the field "hey123" and then click submit, the form will show the appropriate validation error message next to the text field, but the text field itself won't contain my previous entry of hey123, it will show the First Name text again. 因此,基本上,如果我要输入“ hey123”字段,然后单击“提交”,则表单将在文本字段旁边显示相应的验证错误消息,但是文本字段本身不会包含我以前的hey123输入,将再次显示名字文本。

Is it possible to have the input field show the default value initially while also allowing whatever the user entered into the form to be preserved when validation errors occur? 是否可以使输入字段最初显示默认值,同时还允许在发生验证错误时保留用户输入表单的所有内容? So in the previous example, instead of showing the First Name text on the error validation page, it'd show my original entry that caused the issue, hey123. 因此,在上一个示例中,没有显示错误验证页面上的“名字”文本,而是显示了引起问题的原始条目hey123。

Use: 采用:

<?php
    echo $this->Form->input('first_name', array('default' =>'First Name', 'label' => false));
?>

Note, use default instead of value . 注意,使用default代替value Default will set a 'default' value, while value will explicitly set the value of that field. Default将设置一个“默认”值,而value将显式设置该字段的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM