terminal42 / contao-ajaxform
Contao开源CMS的Ajax表单扩展
1.3.1
2024-07-03 11:35 UTC
Requires
- php: ^7.4 || ^8.0
- contao-community-alliance/composer-plugin: ^2.4.1 || ~3.0
- contao/core-bundle: ^4.9 || 5.0.*
README
🚨 当Contao 4.13 LTS达到EOL时,此扩展将不再受支持。这是因为我们已经将此功能贡献给了Contao Core。您可以从Contao版本5.1开始使用它,因此您将不再需要此扩展 🎉
允许您通过Ajax提交使用内置表单生成器生成的表单。安装后,您将有一个名为“带有Ajax的表单”的新内容元素。只需选择它并享受魔法吧。
它还支持重定向,因此您可以与例如"mp_forms"结合使用。
此扩展不需要jQuery或MooTools,因此仅在现代浏览器中工作。
从contao-ajaxform迁移到5.1版Contao Core功能的迁移
手动迁移非常简单
首先,搜索所有类型为ajaxform
的内容元素。如果您想在数据库级别进行操作,可以运行SELECT * FROM tl_content WHERE type='ajaxform'
。然后,为每个元素执行以下步骤
- 将确认
text
复制到剪贴板。 - 转到相应的表单,启用新的Ajax确认消息功能,并将您的确认文本粘贴进去。
- 将
ajaxform
内容元素替换为常规的form
内容元素。 - 卸载扩展。
您也可以通过在您的应用程序中使用Contao迁移框架来自动化它。所需的迁移看起来像这样
namespace App\Migration; use Contao\CoreBundle\Migration\AbstractMigration; use Contao\CoreBundle\Migration\MigrationResult; use Doctrine\DBAL\Connection; class AjaxFormMigration extends AbstractMigration { public function __construct(private readonly Connection $connection) { } public function shouldRun(): bool { $schemaManager = $this->connection->createSchemaManager(); if (!$schemaManager->tablesExist(['tl_content', 'tl_form'])) { return false; } $columns = $schemaManager->listTableColumns('tl_form'); if (!isset($columns['ajax'], $columns['confirmation'])) { return false; } $total = $this->connection->fetchOne('SELECT COUNT(*) FROM tl_content WHERE type=?', ['ajaxform']); return $total > 0; } public function run(): MigrationResult { $records = $this->connection->fetchAllAssociative('SELECT id, form, text FROM tl_content WHERE type=?', ['ajaxform']); foreach ($records as $record) { $this->connection->update('tl_content', ['type' => 'form'], ['id' => $record['id']]); $this->connection->update('tl_form', ['confirmation' => $record['text'], 'ajax' => 1], ['id' => $record['form']]); } return $this->createResult(true); } }