html - Symfony 表单 : how to set default value for a textarea widget

标签 html forms symfony1 textarea

我在 Ubuntu 9.10 上使用 Symfony 1.3.2

我想设置文本区域小部件的默认值,并从 adb 读取数据。

我在模板中的代码片段如下所示:

<?php $form['notes']->render(); ?>

API 文档没有显示如何执行此操作 - 有人知道如何执行此操作吗?

最佳答案

您可以在您的操作或表单类中使用它:

$this->form = new yourForm(); // If its in your action

$text = // data for prepopulating field, from db or anywhere

$this->form->setDefault('notes', $text);

...或者如果您有多个字段:

$this->form->setDefaults(array('notes' => $text, 'more_notes' => $more_text));

或者,如果您更喜欢在表单类配置中使用小部件只声明一次(我认为这是正确的):

$this->setWidgets(array(
  // widgets
  'notes' => new sfWidgetFormTextArea(array('default' => $text)),
  // widgets
));

关于html - Symfony 表单 : how to set default value for a textarea widget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2753444/

相关文章:

html - href ="tel:"和手机号码

css - 如何使用内联 CSS 更改链接文本的字体颜色?

html - 垂直对齐 :top not working in td with multiple elements

html - 使占位符仅在所有浏览器中输入文本后消失

php - 让所有表单验证错误都显示在 symfony 的顶部?

php - Symfony 1.4 sfDoctrinePager : How to set custom SQL?

javascript - Jstree 无法正确渲染

html - 将鼠标悬停在工具提示上?无法让它与顶部导航栏中的列表一起使用?

jquery - 更改表单的 'action'

forms - 使用 AngularJS 比较表单验证中的两个输入值