qbus/contao-configform-bundle

使用配置文件而不是表单生成器来定义表单。

0.2.0 2018-11-28 14:42 UTC

This package is auto-updated.

Last update: 2024-09-24 04:54:49 UTC


README

使用配置文件而不是表单生成器来定义表单。这使得表单更容易移植。

由于这些表单是通过Contao核心渲染、验证和处理的,因此它们的行为与表单生成器表单相同。例如

  • 表单钩子,如compileFormFieldsprepareFormData,是可用的;
  • 可以使用表单设置,如sendViaEmail

示例用法

创建一个配置文件templates/[theme-name/]formconfig_contact.php

<?php

return [
	'tl_form' => [
		'title' => 'Contact',
		'sendViaEmail' => true,
		'format' => 'email',
		'subject' => 'Contact via website form',
		'tableless' => true
	],
	'tl_form_field' => [
		[
			'type' => 'text',
			'name' => 'email',
			'label' => 'Email',
			'mandatory' => true,
			'rgxp' => 'email'
		],
		[
			'type' => 'text',
			'name' => 'subject',
			'label' => 'Subject',
			'mandatory' => true
		],
		[
			'type' => 'textarea',
			'name' => 'message',
			'label' => 'Message',
			'mandatory' => true,
			'size' => serialize([8,12])
		],
		[
			'type' => 'submit',
			'slabel' => 'Send'
		]
	]
];

在Contao后端,创建一个类型为从配置文件创建表单的前端模块,并选择该配置。

在任何需要插入表单的地方使用该模块。