Add callback feature to form elements, no JS needed

Created on 4 October 2025, 6 days ago

Problem/Motivation

The ajax callbacks are pretty nice to work with, I'd like the same for non-js forms.

This is meant to help with the htmx initiative, Ideally we would not have different code path to handle ajax and non-ajax forms.

Steps to reproduce

Proposed resolution

Add a new #callback render array key, that is used whenever _trigger_element_name and _trigger_element_value corresponds.

// for an htmx-submitted form we can just do:
    $form['type'] = [
      '#type' => 'select',
      '#title' => 'Type',
      '#empty_value' => '',
      '#options' => [
        'a' => 'A',
        'b' => 'B',
      ],
      '#default_value' => $type,
      '#callback' => [static::class, 'test'],
    ];

// for a non-js form
    $form['test'] = [
      '#type' => 'button',
      '#button_type' => 'submit',
      '#name' => '_triggering_element_name',
      '#value' => 'TEST!',
      '#callback' => [static::class, 'testsubmit'],
    ];

// We can also trigger a callback from an other element, similar to #ajax 'trigger_as'
    $form['test'] = [
      '#type' => 'button',
      '#button_type' => 'submit',
      '#name' => '_triggering_element_name',
      '#value' => 'type',
    ];

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Feature request
Status

Active

Version

11.0 🔥

Component

forms system

Created by

🇫🇷France nod_ Lille

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Merge request !13410Resolve #3550306 "Add callback feature" → (Open) created by nod_
  • Pipeline finished with Failed
    6 days ago
    Total: 136s
    #618315
  • Pipeline finished with Failed
    6 days ago
    Total: 262s
    #618316
  • Pipeline finished with Failed
    5 days ago
    Total: 238s
    #618481
  • Pipeline finished with Failed
    3 days ago
    Total: 141s
    #621050
Production build 0.71.5 2024