有没有办法在表单中更改标签的位置?我想把它放在输入字段(sfWidgetFormInputText和sfWidgetFormChoice)之上。这可能吗?
答案 0 :(得分:2)
取决于您如何呈现表单字段。您可以通过以下几种方式实现:
如果要以与表单中其余字段不同的方式呈现单个字段,可以在模板中单独呈现标签和窗口小部件:
// \apps\myApp\modules\myModule\templates\_form.php
echo $form['field_name']->renderLabel(); // Render the label
echo $form['field_name']->render(); // Render the widget
echo $form['field_name']->renderError(); // Render the error
echo $form['field_name']->renderHelp(); // Render the help message
如果要在整个表单中应用布局。您应该创建一个新的格式化程序类并将其应用于表单:
// \lib\form\formatter\sfWidgetFormSchemaFormatterCustom.class.php
class sfWidgetFormSchemaFormatterCustom extends sfWidgetFormSchemaFormatter
{
protected
$rowFormat = '<div class="label">%label%</div><div class="field">%field%</div>%error% \n %help %hidden_fields%',
$errorRowFormat = '<div>%errors%</div>',
$helpFormat = '<div class="form_help">%help%</div>',
$decoratorFormat = '<div>\n %content%</div>';
}
将它应用于表单的配置方法,如下所示:
// \lib\form\myForm.class.php
public function configure()
{
//....
$formatter = new sfWidgetFormSchemaFormatterCustom($this->getWidgetSchema());
$this->widgetSchema->addFormFormatter('custom', $formatter);
$this->widgetSchema->setFormFormatterName('custom');
}
如果希望在项目中全局使用格式化程序,可以将其设置为ProjectConfiguration.class.php中的默认格式化程序。
// \config\ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
// ...
sfWidgetFormSchema::setDefaultFormFormatterName('custom');
}
}
答案 1 :(得分:0)
您必须在与您可以使用html标记(template
,<th>
,<tr>
重新组织所有表单的表单关联的<td>
中执行此操作。 ..)。