定制 pawsitiwe/sulu-forms-ajax-validation-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pawsitiwe/sulu-forms-ajax-validation-bundle

最新稳定版本:0.2.1

Composer 安装命令:

composer require pawsitiwe/sulu-forms-ajax-validation-bundle

包简介

A bundle for Sulu form ajax validation

README 文档

README

Installation

composer require pawsitiwe/sulu-forms-ajax-validation-bundle

Setup

Service Registration

The extension needs to be registered as symfony service.

services:
    Pawsitiwe\Controller\ValidationController:
        arguments:
            $formBuilder: '@sulu_form.builder'
        tags: ['controller.service_arguments']

Bundle Registration

return [
    Pawsitiwe\SuluFormsAjaxValidationBundle::class => ['all' => true],
]

Route Registration

sulu_frontend_validation:
    resource: '@SuluFormsAjaxValidationBundle/Resources/config/routes.yaml'
    prefix: /

Usage

The route /ajax/form/validate returns the form validation as JSON

Twig Integration

Include the AJAX-enabled form in your templates using the provided partial:

{% include '@SuluFormsAjaxValidation/forms/partials/ajax_form.html.twig' with {
    form: content.form,
    successText: view.form.entity.successText,
    errorText: 'Custom error message' # optional
} %}

This partial automatically:

  • Uses the custom form theme ajax_form.html.twig
  • Displays error and success messages
  • Adds type-specific and additional CSS classes for styling

Example Response

{
    "message": "",
    "valid": false,
    "fields": [
        {
            "id": "dynamic_form1_email",
            "valid": false,
            "modified": true,
            "violation": {
                "message": "This value should not be blank."
            }
        },
        {
            "id": "dynamic_form1_lastName",
            "valid": true,
            "modified": false
        }
    ]
}

Notes

  • The form parameter must be a Sulu Form object.
  • successText is optional; if empty, the default translation ajax_form.success will be used.
  • errorText is optional; if empty, the default translation ajax_form.error will be used.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: Twig

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-18