繁体   English   中英

如何在fuelphp中管理多个表单模板

[英]how to manage multiple form templates in fuelphp

您好,我刚刚从CI迁移到Fuel。...我正在使用Fieldset类在视图中自动生成表单。...我面临的问题是我有多种类型的表单模板,即我的某些模型使用了twitter bootstrap水平内联表单,其中很少有模型使用自定义模板...我能够在form.php中设置表单模板的单一类型,将其从fuel / core / config / form.php复制到fuel / app / config / form.php

这是表单模板的示例返回数组

return array(
// regular form definitions
'prep_value'                 => true,
'auto_id'                    => true,
'auto_id_prefix'             => 'form_',
'form_method'                => 'post',
'form_template'              => "\n\t\t{open}\n\t\t<table>\n{fields}\n\t\t</table>\n\t\t{close}\n",
'fieldset_template'          => "\n\t\t<tr><td colspan=\"2\">{open}<table>\n{fields}</table></td></tr>\n\t\t{close}\n",
'field_template'             => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{field} <span>{description}</span> {error_msg}</td>\n\t\t</tr>\n",
'multi_field_template'       => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{group_label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{fields}\n\t\t\t\t{field} {label}<br />\n{fields}<span>{description}</span>\t\t\t{error_msg}\n\t\t\t</td>\n\t\t</tr>\n",
'error_template'             => '<span>{error_msg}</span>',
'group_label'                => '<span>{label}</span>',
'required_mark'              => '*',
'inline_errors'              => false,
'error_class'                => null,
'label_class'                => null,

// tabular form definitions
'tabular_form_template'      => "<table>{fields}</table>\n",
'tabular_field_template'     => "{field}",
'tabular_row_template'       => "<tr>{fields}</tr>\n",
'tabular_row_field_template' => "\t\t\t<td>{label}{required}&nbsp;{field} {error_msg}</td>\n",
'tabular_delete_label'       => "Delete?",

);

我想要这样的多个表单模板,以便我可以使用$ fieldset-> form()-> build()函数自动生成需要的表单...

有什么办法吗?

是。 尝试这个:

forge($ name ='default',$ config = array());

$article_form = Fieldset::forge('article',array(
// regular form definitions
'prep_value'                 => true,
'auto_id'                    => true,
'auto_id_prefix'             => 'form_',
'form_method'                => 'post',
'form_template'              => "\n\t\t{open}\n\t\t<table>\n{fields}\n\t\t</table>\n\t\t{close}\n",
'fieldset_template'          => "\n\t\t<tr><td colspan=\"2\">{open}<table>\n{fields}</table></td></tr>\n\t\t{close}\n",
'field_template'             => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{field} <span>{description}</span> {error_msg}</td>\n\t\t</tr>\n",
'multi_field_template'       => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{group_label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{fields}\n\t\t\t\t{field} {label}<br />\n{fields}<span>{description}</span>\t\t\t{error_msg}\n\t\t\t</td>\n\t\t</tr>\n",
'error_template'             => '<span>{error_msg}</span>',
'group_label'                => '<span>{label}</span>',
'required_mark'              => '*',
'inline_errors'              => false,
'error_class'                => null,
'label_class'                => null,

// tabular form definitions
'tabular_form_template'      => "<table>{fields}</table>\n",
'tabular_field_template'     => "{field}",
'tabular_row_template'       => "<tr>{fields}</tr>\n",
'tabular_row_field_template' => "\t\t\t<td>{label}{required}&nbsp;{field} {error_msg}</td>\n",
'tabular_delete_label'       => "Delete?",
));

暂无
暂无

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

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