Skip to main content
3 of 3
typos, better image placement, title
sanzante
  • 7k
  • 3
  • 29
  • 42

Submit button not triggering a form submit

I have a strange phenomenon. The code seams to be correct but the submit button is not triggered. dpm says the callback functions are loaded correctly in the $form value like this:

dpm out of $form

When I pressed one of the buttons nothing happened. I do not get any error message or log entry.

Any solution or ide for debuging?

CODE:

/**
* Implements hook_menu().
*/
function payu_ui_menu() {
  $items = array();
  $items['admin/config/services/payu/merchant'] = array(
    'title' => 'PayU merchant settings',
    'access callback' => 'user_access',
    'access arguments' => array('payu_administer'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('payu_merchant_settings_form'),
     'description' =>  '',
    //'type' => MENU_NORMAL_ITEM,
    'type' => MENU_CALLBACK,
  );
  $items['admin/config/services/payu/merchant/%payu_merchant'] = array(
    'title callback' => 'payu_merchant_edit_form_title',
    'title arguments' => array(5),
    'access callback' => 'user_access',
    'access arguments' => array('payu_administer'),
    'page callback' => 'payu_merchant_edit_form',
    'page arguments' => array(5),
    'description' =>  '',
    //'type' => MENU_VISIBLE_IN_BREADCRUMB,
    'type' => MENU_CALLBACK,
  );
  $items['admin/config/services/payu/merchant/%payu_merchant/delete'] = array(
    'title' => 'Delete',
    'access callback' => 'user_access',
    'access arguments' => array('payu_administer'),
    'page callback' => 'payu_merchant_delete_confirm_form',
    'page arguments' => array(5),
    'description' =>  '',
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
  );
  return $items;
}

...

/**
 * Payu merchant settings form validate.
 */
function payu_merchant_settings_form_validate(&$form, &$form_state) {
  drupal_set_message('Settings validate');
  $form_state['values']['merchant_id'] = trim($form_state['values']['merchant_id']);
  $form_state['values']['secret_key'] = trim($form_state['values']['secret_key']);
  $merchant_id = $form_state['values']['merchant_id'];
  if (substr($merchant_id, 0, 1) === 'P' && !ctype_digit(substr($merchant_id, 1, 6))) {
    form_set_error('merchant_id', t('Merchant ID always start with "P" and 6 digits'));
  }
  elseif (substr($merchant_id, 0, 1) === 'P' && strlen($merchant_id) != 7) {
    form_set_error('merchant_id', t('Merchant ID length is always 7 character!'));
  }
  if (!isset($form['#merchant'])) {
    // new item from "add merchant" form
    $merchant = ($merchant_id);
    if (!empty($merchant)) {
      form_set_error('merchant_id', t('Merchant ID is unique!'));
    }
  }
}

/**
 * Edit merchant settings.
 */
function payu_merchant_edit_form($merchant) {
   $form['#merchant'] = $merchant;
   $form['merchant_id'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => t('Merchant ID'),
    '#default_value' => $merchant->merchant_id,
    '#value' => $merchant->merchant_id,
    '#size' => 7,
    '#maxlength' => 7,
  );
  $form['secret_key'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => t('Secret key'),
    '#default_value' => $merchant->secret_key,
    '#value' => $merchant->secret_key,
    '#size' => 32,
    '#maxlength' => 32,
  );
  $form['currency'] = array(
    '#type' => 'select',
    '#required' => TRUE,
    '#title' => t('Currency'),
    '#options' => variable_get('payu_currencies'),
    '#default_value' => $merchant->currency,
    '#value' => $merchant->currency,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#required' => FALSE,
    '#title' => t('Merchant name'),
    '#default_value' => $merchant->name,
    '#value' => $merchant->name,
    '#size' => 64,
    '#maxlength' => 64,
  );
  $form['actions'] = array(
    '#type' => 'actions',
    'submit' => array(
      '#type' => 'submit',
      '#value' => t('Save'),
      "#executes_submit_callback" => TRUE,
      '#validate' => array('payu_merchant_settings_form_validate'),
      '#submit' => array('payu_merchant_edit_save_submit'),
    ),
    'delete' => array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      "#executes_submit_callback" => TRUE,
      '#submit' => array('payu_merchant_edit_delete_submit'),
    ),
  );
  return $form;
}

/**
 * Save edited merchant data.
 */
function payu_merchant_edit_save_submit($form, $form_state) {
  drupal_set_message('saving');
  $currencies = variable_get('payu_currencies', array());
  $result = db_merge('payu_merchants')
    ->key(array(
      'merchant_id' => $form_state['values']['merchant_id'],
    ))
    ->fields(array(
      'merchant_id' => $form_state['values']['merchant_id'],
      'secret_key' => $form_state['values']['secret_key'],
      'currency' => $currencies[$form_state['values']['currency']],
      'name' => $form_state['values']['name'],
    ))
    ->execute();
  switch ($result) {
    case MergeQuery::STATUS_INSERT:
      drupal_set_message(t('PayU merchant: %merchant_id added.', array('%merchant_id' => $form_state['values']['merchant_id'])));
      break;

    case MergeQuery::STATUS_UPDATE:
      drupal_set_message(t('PayU merchant: %merchant_id updated.', array('%merchant_id' => $form_state['values']['merchant_id'])));
      break;
  }
  $form_state['redirect'] = array('admin/config/services/payu/merchant');
}

/**
 * Delete merchant: menu callback function.
 */
function payu_merchant_edit_delete_submit(&$form, &$form_state) {
  $merchant = $form['#merchant'];
  $form_state['redirect'] = array('admin/config/services/payu/merchant/' . $merchant->merchant_id . '/delete');
}

/**
 * Delete merchant data: confirm form.
 */
function payu_merchant_delete_confirm_form($merchant) {
  $form['#merchant'] = $merchant;
  dpm($merchant);
  return confirm_form($form, t('Are you sure delete "%merchant_id" merchant?', array('%merchant_id' => $merchant->merchant_id)), 'admin/config/services/payu/merchant');
}

/**
 * Delete merchant data.
 */
function payu_merchant_delete_confirm_form_submit(&$form, &$form_state) {
  $merchant = $form['#merchant'];
  //drupal_set_message($merchant->merchant_id);
  db_delete('payu_merchants')
    ->condition('merchant_id', $merchant->merchant_id)
    ->execute();
  drupal_set_message(t('PayU merchant: %merchant_id deleted.', array('%merchant_id' => $merchant->merchant_id)));
 //$form_state['redirect'] = array('admin/config/services/payu/merchant');
}

html source