3 improved formatting
source | link

Form: Custom submit callbacksubmission handler is not called

I have a form with a second button which should add new form elements according to this page. The callback does not get called though. The second button is configured as follows:set from the following code.

$form[ 'addTicket' ] = array(
    '#type' => 'submit',
    '#submit' => array( 'asdf' ),
    '#value' => 'Add Ticket'
);

Clicking it should, as of my understanding, call this callback function:.

function asdf()
  {
    error_log( 'I was called' );
}

Update: Full code This is herethe complete code.

<?php

function WPD14_menu()
  {
    $items = array();
    $items[ 'WPD14/anmeldung' ] = array(
        'title' => 'Anmeldung zum World Photography Day 2014',
        'page callback' => 'WPD14_anmeldung',
        'access arguments' => array( 'access content' ),
        'description' => 'Anmeldung zum WPD 14',
        'type' => MENU_CALLBACK,
    );
    return $items;
}

function WPD14_anmeldung()
  {
    return drupal_get_form( 'WPD14_anmeldeformular' );
}

function asdf($form, &$form_state )
  {
    error_log( 'asdfasdfasdfs' );
}

function WPD14_anmeldeformular( $form_state )
  {
 
    $form[ 'buyer' ]$form['buyer'] = array(
        '#type' => 'fieldset',
        '#title' => 'Infos',
    );
    $form[ 'buyer' ][ 
 'strasse' ]$form['buyer']['strasse'] = array(
        '#type' => 'textfield',
        '#title' => 'Strasse + Nr.',
        '#required' => TRUE,
        '#default_value' => isset( $form_state[ 'storage' ][ 'buyer' ][ 'strasse' ] $form_state['storage']['buyer']['strasse']) ? $form_state[ 'storage' ][ 'buyer' ][ 'strasse' ]$form_state['storage']['buyer']['strasse'] : 'Strasse',
    );
    $form[ 'buyer' ][ 
 'plz' ]$form['buyer']['plz'] = array(
        '#type' => 'textfield',
        '#title' => 'PLZ',
        '#required' => TRUE,
        '#default_value' => '1234'
    );
    $form[ 'buyer' 
 ][ 'ort' ]$form['buyer']['ort'] = array(
        '#type' => 'textfield',
        '#title' => 'Ort',
        '#required' => TRUE,
        '#default_value' => 'There'
    );
    $form[ 'buyer' ][ 
 'mail' ]$form['buyer']['mail'] = array(
        '#type' => 'textfield',
        '#title' => 'Mailadresse',
        '#required' => TRUE,
        '#default_value' => 'test@example.com',
    );

    $nTickets = isset( $form_state[ 'storage' ][ 'nTickets' ] $form_state['storage']['nTickets']) ? intval( $form_state[ 'storage' ][ 'nTickets' ] $form_state['storage']['nTickets']) : 2;
    $nTickets = min( 20, max( 1, $nTickets ) );

    $form[ 'nTickets' ]$form['nTickets'] = array(
        '#type' => 'textfield',
        '#title' => 'Anzahl Tickets',
        '#disabled' => FALSE,
        '#default_value' => $nTickets,
    );

    for ( $t = 0; $t < $nTickets; $t++ ) {
        $form[ 'tickets' ][ $t ]$form['tickets'][$t] = WPD14_ticketformular( $t );
    }

    $form[ 'addTicket' ]$form['addTicket'] = array(
        '#type' => 'submit',
        '#submit' => array( 'WPD14_anmeldeformular_addTicket', 'asdf' ),
        '#value' => 'Weiteres Ticket'
    );

    $form[ 'submit' ]$form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Anmelden',
    );

    return $form;
}

function WPD14_anmeldeformular_addTicket( $form, &$form_state )
  {
    error_log( 'Callback called.' );
    error_log( $form_state[ 'nTickets' ] $form_state['nTickets']);
    $form_state[ 'nTickets' ]++;$form_state['nTickets']++;
    // $form_state['rebuild'] = TRUE;
    drupal_set_message( $form_state[ 'nTickets' ] $form_state['nTickets']);
}

function WPD14_ticketformular( $nr )
  {
    $form = array(
        'vorname-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Vorname',
            '#required' => TRUE,
            '#default_value' => 'Vorname ' . $nr
        ),
        'nachname-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Nachname',
            '#required' => TRUE,
            '#default_value' => 'Nachname ' . $nr
        ),
        'frMain-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Hauptvortrag Freitag',
            '#required' => TRUE,
            '#default_value' => 'Fr H ' . $nr
        ),
        'saDay-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Nachmittagsvorträge',
            '#required' => TRUE,
            '#default_value' => 'Sa ' . $nr
        ),
        'saMain-' . $nr => array(
            '#type' => 'Hauptvortrag Samstag',
            '#title' => 'Name',
            '#required' => TRUE,
            '#default_value' => 'Sa H ' . $nr
        ),
    );
   
  return $form;
}


function WPD14_anmeldeformular_validate( $form, &$form_state )
 {
 
    if ( !preg_match( '/^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\\.[a-z]{2,4}$/', $form_state[ 'values' ][ 'mail' ] $form_state['values']['mail']) ) {
        form_set_error( 'mail', 'Bitte geben Sie eine gültige Mailadresse an.' );
    }

    $nTickets = intval( $form_state[ 'values' ][ 'nTickets' ] $form_state['values']['nTickets']);
    if ( $nTickets < 1 ) {
        form_set_error( 'nTickets', 'Kein Ticket ausgewählt.' );
    }

    form_set_error( 'debug', print_r( $form_state, TRUE ) );
 
}

Form: Custom submit callback is not called

I have a form with a second button which should add new form elements according to this page. The callback does not get called though. The second button is configured as follows:

$form[ 'addTicket' ] = array(
    '#type' => 'submit',
    '#submit' => array( 'asdf' ),
    '#value' => 'Add Ticket'
);

Clicking it should, as of my understanding, call this callback function:

function asdf()
 {
    error_log( 'I was called' );
}

Update: Full code is here.

<?php

function WPD14_menu()
 {
    $items = array();
    $items[ 'WPD14/anmeldung' ] = array(
        'title' => 'Anmeldung zum World Photography Day 2014',
        'page callback' => 'WPD14_anmeldung',
        'access arguments' => array( 'access content' ),
        'description' => 'Anmeldung zum WPD 14',
        'type' => MENU_CALLBACK,
    );
    return $items;
}

function WPD14_anmeldung()
 {
    return drupal_get_form( 'WPD14_anmeldeformular' );
}

function asdf($form, &$form_state )
 {
    error_log( 'asdfasdfasdfs' );
}

function WPD14_anmeldeformular( $form_state )
 {
 
    $form[ 'buyer' ] = array(
        '#type' => 'fieldset',
        '#title' => 'Infos',
    );
    $form[ 'buyer' ][ 'strasse' ] = array(
        '#type' => 'textfield',
        '#title' => 'Strasse + Nr.',
        '#required' => TRUE,
        '#default_value' => isset( $form_state[ 'storage' ][ 'buyer' ][ 'strasse' ] ) ? $form_state[ 'storage' ][ 'buyer' ][ 'strasse' ] : 'Strasse',
    );
    $form[ 'buyer' ][ 'plz' ] = array(
        '#type' => 'textfield',
        '#title' => 'PLZ',
        '#required' => TRUE,
        '#default_value' => '1234'
    );
    $form[ 'buyer' ][ 'ort' ] = array(
        '#type' => 'textfield',
        '#title' => 'Ort',
        '#required' => TRUE,
        '#default_value' => 'There'
    );
    $form[ 'buyer' ][ 'mail' ] = array(
        '#type' => 'textfield',
        '#title' => 'Mailadresse',
        '#required' => TRUE,
        '#default_value' => 'test@example.com',
    );

    $nTickets = isset( $form_state[ 'storage' ][ 'nTickets' ] ) ? intval( $form_state[ 'storage' ][ 'nTickets' ] ) : 2;
    $nTickets = min( 20, max( 1, $nTickets ) );

    $form[ 'nTickets' ] = array(
        '#type' => 'textfield',
        '#title' => 'Anzahl Tickets',
        '#disabled' => FALSE,
        '#default_value' => $nTickets,
    );

    for ( $t = 0; $t < $nTickets; $t++ ) {
        $form[ 'tickets' ][ $t ] = WPD14_ticketformular( $t );
    }

    $form[ 'addTicket' ] = array(
        '#type' => 'submit',
        '#submit' => array( 'WPD14_anmeldeformular_addTicket', 'asdf' ),
        '#value' => 'Weiteres Ticket'
    );

    $form[ 'submit' ] = array(
        '#type' => 'submit',
        '#value' => 'Anmelden',
    );

    return $form;
}

function WPD14_anmeldeformular_addTicket( $form, &$form_state )
 {
    error_log( 'Callback called.' );
    error_log( $form_state[ 'nTickets' ] );
    $form_state[ 'nTickets' ]++;
    //$form_state['rebuild'] = TRUE;
    drupal_set_message( $form_state[ 'nTickets' ] );
}

function WPD14_ticketformular( $nr )
 {
    $form = array(
        'vorname-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Vorname',
            '#required' => TRUE,
            '#default_value' => 'Vorname ' . $nr
        ),
        'nachname-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Nachname',
            '#required' => TRUE,
            '#default_value' => 'Nachname ' . $nr
        ),
        'frMain-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Hauptvortrag Freitag',
            '#required' => TRUE,
            '#default_value' => 'Fr H ' . $nr
        ),
        'saDay-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Nachmittagsvorträge',
            '#required' => TRUE,
            '#default_value' => 'Sa ' . $nr
        ),
        'saMain-' . $nr => array(
            '#type' => 'Hauptvortrag Samstag',
            '#title' => 'Name',
            '#required' => TRUE,
            '#default_value' => 'Sa H ' . $nr
        ),
    );
    return $form;
}


function WPD14_anmeldeformular_validate( $form, &$form_state )
 {
 
    if ( !preg_match( '/^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\\.[a-z]{2,4}$/', $form_state[ 'values' ][ 'mail' ] ) ) {
        form_set_error( 'mail', 'Bitte geben Sie eine gültige Mailadresse an.' );
    }

    $nTickets = intval( $form_state[ 'values' ][ 'nTickets' ] );
    if ( $nTickets < 1 ) {
        form_set_error( 'nTickets', 'Kein Ticket ausgewählt.' );
    }

    form_set_error( 'debug', print_r( $form_state, TRUE ) );
 
}

Custom submission handler is not called

I have a form with a second button which should add new form elements according to this page. The callback does not get called though. The second button is set from the following code.

$form[ 'addTicket' ] = array(
  '#type' => 'submit',
  '#submit' => array('asdf'),
  '#value' => 'Add Ticket'
);

Clicking it should, as of my understanding, call this callback function.

function asdf() {
  error_log( 'I was called' );
}

This is the complete code.

function WPD14_menu() {
    $items = array();
    $items[ 'WPD14/anmeldung' ] = array(
        'title' => 'Anmeldung zum World Photography Day 2014',
        'page callback' => 'WPD14_anmeldung',
        'access arguments' => array( 'access content' ),
        'description' => 'Anmeldung zum WPD 14',
        'type' => MENU_CALLBACK,
    );
    return $items;
}

function WPD14_anmeldung() {
  return drupal_get_form('WPD14_anmeldeformular');
}

function asdf($form, &$form_state) {
  error_log('asdfasdfasdfs');
}

function WPD14_anmeldeformular($form_state) {
  $form['buyer'] = array(
    '#type' => 'fieldset',
    '#title' => 'Infos',
  );
 
  $form['buyer']['strasse'] = array(
    '#type' => 'textfield',
    '#title' => 'Strasse + Nr.',
    '#required' => TRUE,
    '#default_value' => isset($form_state['storage']['buyer']['strasse']) ? $form_state['storage']['buyer']['strasse'] : 'Strasse',
  );
 
  $form['buyer']['plz'] = array(
    '#type' => 'textfield',
    '#title' => 'PLZ',
    '#required' => TRUE,
    '#default_value' => '1234'
  );
 
  $form['buyer']['ort'] = array(
    '#type' => 'textfield',
    '#title' => 'Ort',
    '#required' => TRUE,
    '#default_value' => 'There'
  );
 
  $form['buyer']['mail'] = array(
    '#type' => 'textfield',
    '#title' => 'Mailadresse',
    '#required' => TRUE,
    '#default_value' => 'test@example.com',
  );

  $nTickets = isset($form_state['storage']['nTickets']) ? intval( $form_state['storage']['nTickets']) : 2;
  $nTickets = min(20, max(1, $nTickets));

  $form['nTickets'] = array(
    '#type' => 'textfield',
    '#title' => 'Anzahl Tickets',
    '#disabled' => FALSE,
    '#default_value' => $nTickets,
  );

  for ($t = 0; $t < $nTickets; $t++) {
    $form['tickets'][$t] = WPD14_ticketformular($t);
  }

  $form['addTicket'] = array(
    '#type' => 'submit',
    '#submit' => array( 'WPD14_anmeldeformular_addTicket', 'asdf' ),
    '#value' => 'Weiteres Ticket'
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Anmelden',
  );

  return $form;
}

function WPD14_anmeldeformular_addTicket($form, &$form_state) {
  error_log('Callback called.');
  error_log($form_state['nTickets']);
  $form_state['nTickets']++;
  // $form_state['rebuild'] = TRUE;
  drupal_set_message($form_state['nTickets']);
}

function WPD14_ticketformular($nr) {
  $form = array(
    'vorname-' . $nr => array(
      '#type' => 'textfield',
      '#title' => 'Vorname',
      '#required' => TRUE,
      '#default_value' => 'Vorname ' . $nr
    ),
    'nachname-' . $nr => array(
      '#type' => 'textfield',
      '#title' => 'Nachname',
      '#required' => TRUE,
      '#default_value' => 'Nachname ' . $nr
    ),
    'frMain-' . $nr => array(
      '#type' => 'textfield',
      '#title' => 'Hauptvortrag Freitag',
      '#required' => TRUE,
      '#default_value' => 'Fr H ' . $nr
    ),
    'saDay-' . $nr => array(
      '#type' => 'textfield',
      '#title' => 'Nachmittagsvorträge',
      '#required' => TRUE,
      '#default_value' => 'Sa ' . $nr
    ),
    'saMain-' . $nr => array(
      '#type' => 'Hauptvortrag Samstag',
      '#title' => 'Name',
      '#required' => TRUE,
      '#default_value' => 'Sa H ' . $nr
    ),
  );
 
  return $form;
}


function WPD14_anmeldeformular_validate($form, &$form_state){
  if (!preg_match( '/^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\\.[a-z]{2,4}$/', $form_state['values']['mail'])) {
    form_set_error('mail','Bitte geben Sie eine gültige Mailadresse an.');
  }

  $nTickets = intval($form_state['values']['nTickets']);
  if ($nTickets < 1) {
    form_set_error('nTickets','Kein Ticket ausgewählt.');
  }

  form_set_error('debug', print_r($form_state, TRUE));
}
2 added 4939 characters in body
source | link

Update: Full code is here.

<?php

function WPD14_menu()
{
    $items = array();
    $items[ 'WPD14/anmeldung' ] = array(
        'title' => 'Anmeldung zum World Photography Day 2014',
        'page callback' => 'WPD14_anmeldung',
        'access arguments' => array( 'access content' ),
        'description' => 'Anmeldung zum WPD 14',
        'type' => MENU_CALLBACK,
    );
    return $items;
}

function WPD14_anmeldung()
{
    return drupal_get_form( 'WPD14_anmeldeformular' );
}

function asdf($form, &$form_state )
{
    error_log( 'asdfasdfasdfs' );
}

function WPD14_anmeldeformular( $form_state )
{

    $form[ 'buyer' ] = array(
        '#type' => 'fieldset',
        '#title' => 'Infos',
    );
    $form[ 'buyer' ][ 'strasse' ] = array(
        '#type' => 'textfield',
        '#title' => 'Strasse + Nr.',
        '#required' => TRUE,
        '#default_value' => isset( $form_state[ 'storage' ][ 'buyer' ][ 'strasse' ] ) ? $form_state[ 'storage' ][ 'buyer' ][ 'strasse' ] : 'Strasse',
    );
    $form[ 'buyer' ][ 'plz' ] = array(
        '#type' => 'textfield',
        '#title' => 'PLZ',
        '#required' => TRUE,
        '#default_value' => '1234'
    );
    $form[ 'buyer' ][ 'ort' ] = array(
        '#type' => 'textfield',
        '#title' => 'Ort',
        '#required' => TRUE,
        '#default_value' => 'There'
    );
    $form[ 'buyer' ][ 'mail' ] = array(
        '#type' => 'textfield',
        '#title' => 'Mailadresse',
        '#required' => TRUE,
        '#default_value' => 'test@example.com',
    );

    $nTickets = isset( $form_state[ 'storage' ][ 'nTickets' ] ) ? intval( $form_state[ 'storage' ][ 'nTickets' ] ) : 2;
    $nTickets = min( 20, max( 1, $nTickets ) );

    $form[ 'nTickets' ] = array(
        '#type' => 'textfield',
        '#title' => 'Anzahl Tickets',
        '#disabled' => FALSE,
        '#default_value' => $nTickets,
    );

    for ( $t = 0; $t < $nTickets; $t++ ) {
        $form[ 'tickets' ][ $t ] = WPD14_ticketformular( $t );
    }

    $form[ 'addTicket' ] = array(
        '#type' => 'submit',
        '#submit' => array( 'WPD14_anmeldeformular_addTicket', 'asdf' ),
        '#value' => 'Weiteres Ticket'
    );

    $form[ 'submit' ] = array(
        '#type' => 'submit',
        '#value' => 'Anmelden',
    );

    return $form;
}

function WPD14_anmeldeformular_addTicket( $form, &$form_state )
{
    error_log( 'Callback called.' );
    error_log( $form_state[ 'nTickets' ] );
    $form_state[ 'nTickets' ]++;
    //$form_state['rebuild'] = TRUE;
    drupal_set_message( $form_state[ 'nTickets' ] );
}

function WPD14_ticketformular( $nr )
{
    $form = array(
        'vorname-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Vorname',
            '#required' => TRUE,
            '#default_value' => 'Vorname ' . $nr
        ),
        'nachname-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Nachname',
            '#required' => TRUE,
            '#default_value' => 'Nachname ' . $nr
        ),
        'frMain-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Hauptvortrag Freitag',
            '#required' => TRUE,
            '#default_value' => 'Fr H ' . $nr
        ),
        'saDay-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Nachmittagsvorträge',
            '#required' => TRUE,
            '#default_value' => 'Sa ' . $nr
        ),
        'saMain-' . $nr => array(
            '#type' => 'Hauptvortrag Samstag',
            '#title' => 'Name',
            '#required' => TRUE,
            '#default_value' => 'Sa H ' . $nr
        ),
    );
    return $form;
}


function WPD14_anmeldeformular_validate( $form, &$form_state )
{

    if ( !preg_match( '/^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\\.[a-z]{2,4}$/', $form_state[ 'values' ][ 'mail' ] ) ) {
        form_set_error( 'mail', 'Bitte geben Sie eine gültige Mailadresse an.' );
    }

    $nTickets = intval( $form_state[ 'values' ][ 'nTickets' ] );
    if ( $nTickets < 1 ) {
        form_set_error( 'nTickets', 'Kein Ticket ausgewählt.' );
    }

    form_set_error( 'debug', print_r( $form_state, TRUE ) );

}

Update: Full code is here.

<?php

function WPD14_menu()
{
    $items = array();
    $items[ 'WPD14/anmeldung' ] = array(
        'title' => 'Anmeldung zum World Photography Day 2014',
        'page callback' => 'WPD14_anmeldung',
        'access arguments' => array( 'access content' ),
        'description' => 'Anmeldung zum WPD 14',
        'type' => MENU_CALLBACK,
    );
    return $items;
}

function WPD14_anmeldung()
{
    return drupal_get_form( 'WPD14_anmeldeformular' );
}

function asdf($form, &$form_state )
{
    error_log( 'asdfasdfasdfs' );
}

function WPD14_anmeldeformular( $form_state )
{

    $form[ 'buyer' ] = array(
        '#type' => 'fieldset',
        '#title' => 'Infos',
    );
    $form[ 'buyer' ][ 'strasse' ] = array(
        '#type' => 'textfield',
        '#title' => 'Strasse + Nr.',
        '#required' => TRUE,
        '#default_value' => isset( $form_state[ 'storage' ][ 'buyer' ][ 'strasse' ] ) ? $form_state[ 'storage' ][ 'buyer' ][ 'strasse' ] : 'Strasse',
    );
    $form[ 'buyer' ][ 'plz' ] = array(
        '#type' => 'textfield',
        '#title' => 'PLZ',
        '#required' => TRUE,
        '#default_value' => '1234'
    );
    $form[ 'buyer' ][ 'ort' ] = array(
        '#type' => 'textfield',
        '#title' => 'Ort',
        '#required' => TRUE,
        '#default_value' => 'There'
    );
    $form[ 'buyer' ][ 'mail' ] = array(
        '#type' => 'textfield',
        '#title' => 'Mailadresse',
        '#required' => TRUE,
        '#default_value' => 'test@example.com',
    );

    $nTickets = isset( $form_state[ 'storage' ][ 'nTickets' ] ) ? intval( $form_state[ 'storage' ][ 'nTickets' ] ) : 2;
    $nTickets = min( 20, max( 1, $nTickets ) );

    $form[ 'nTickets' ] = array(
        '#type' => 'textfield',
        '#title' => 'Anzahl Tickets',
        '#disabled' => FALSE,
        '#default_value' => $nTickets,
    );

    for ( $t = 0; $t < $nTickets; $t++ ) {
        $form[ 'tickets' ][ $t ] = WPD14_ticketformular( $t );
    }

    $form[ 'addTicket' ] = array(
        '#type' => 'submit',
        '#submit' => array( 'WPD14_anmeldeformular_addTicket', 'asdf' ),
        '#value' => 'Weiteres Ticket'
    );

    $form[ 'submit' ] = array(
        '#type' => 'submit',
        '#value' => 'Anmelden',
    );

    return $form;
}

function WPD14_anmeldeformular_addTicket( $form, &$form_state )
{
    error_log( 'Callback called.' );
    error_log( $form_state[ 'nTickets' ] );
    $form_state[ 'nTickets' ]++;
    //$form_state['rebuild'] = TRUE;
    drupal_set_message( $form_state[ 'nTickets' ] );
}

function WPD14_ticketformular( $nr )
{
    $form = array(
        'vorname-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Vorname',
            '#required' => TRUE,
            '#default_value' => 'Vorname ' . $nr
        ),
        'nachname-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Nachname',
            '#required' => TRUE,
            '#default_value' => 'Nachname ' . $nr
        ),
        'frMain-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Hauptvortrag Freitag',
            '#required' => TRUE,
            '#default_value' => 'Fr H ' . $nr
        ),
        'saDay-' . $nr => array(
            '#type' => 'textfield',
            '#title' => 'Nachmittagsvorträge',
            '#required' => TRUE,
            '#default_value' => 'Sa ' . $nr
        ),
        'saMain-' . $nr => array(
            '#type' => 'Hauptvortrag Samstag',
            '#title' => 'Name',
            '#required' => TRUE,
            '#default_value' => 'Sa H ' . $nr
        ),
    );
    return $form;
}


function WPD14_anmeldeformular_validate( $form, &$form_state )
{

    if ( !preg_match( '/^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\\.[a-z]{2,4}$/', $form_state[ 'values' ][ 'mail' ] ) ) {
        form_set_error( 'mail', 'Bitte geben Sie eine gültige Mailadresse an.' );
    }

    $nTickets = intval( $form_state[ 'values' ][ 'nTickets' ] );
    if ( $nTickets < 1 ) {
        form_set_error( 'nTickets', 'Kein Ticket ausgewählt.' );
    }

    form_set_error( 'debug', print_r( $form_state, TRUE ) );

}
1
source | link

Form: Custom submit callback is not called

I have a form with a second button which should add new form elements according to this page. The callback does not get called though. The second button is configured as follows:

$form[ 'addTicket' ] = array(
    '#type' => 'submit',
    '#submit' => array( 'asdf' ),
    '#value' => 'Add Ticket'
);

Clicking it should, as of my understanding, call this callback function:

function asdf()
{
    error_log( 'I was called' );
}

It is never called though. Why? Is there a way to debug this?