0

有没有办法改变表格中标签的位置?我想将它放在输入字段上方(sfWidgetFormInputText 和 sfWidgetFormChoice)。那可能吗?

4

2 回答 2

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');
    }
}
于 2013-05-17T02:31:25.420 回答
0

您必须在与表单关联的情况下执行此操作,您可以在其中使用 html 标记 ( , , ....)template重新组织所有表单。<th><tr><td>

于 2013-05-16T15:29:40.083 回答