1

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

2
  • Is there an HTML Element laying over the submit button?
    – sgoelz
    Commented Feb 2, 2016 at 11:43
  • No nothing. I uploaded a screenshot about the html layout. I can click on the button but nothing happened. Commented Feb 2, 2016 at 11:47

1 Answer 1

1

You need to update your merchant edit form menu callback to use drupal_get_form, just like your first one. Or have your menu callback properly build the form.

  $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' => 'drupal_get_form',
    'page arguments' => array('payu_merchant_edit_form', 5),
    'description' =>  '',
    //'type' => MENU_VISIBLE_IN_BREADCRUMB,
    'type' => MENU_CALLBACK,
  );

Drupal is properly rendering your Form API array because it's a render array. However, it is not attaching regular form interaction because it was not built properly.

EDIT: You need to update your form function, as well, for the new parameters.

/**
 * Edit merchant settings.
 */
function payu_merchant_edit_form($form, &$form_state, $merchant) {
...
}
2
  • Thanks Matt, it solve the problem of submit function, but with this solution page argument 5 $merchant is empty. The title callback get the right $merchant value. Commented Feb 2, 2016 at 12:13
  • I forgot to highlight you need to alter the form function. I've added that to answer. See the $form, $form_state parameters that needed to be added. Commented Feb 2, 2016 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.