You are here

function pay_form::form_alter in Pay 7

Same name and namespace in other branches
  1. 6 includes/handlers/pay_form.inc \pay_form::form_alter()

File

includes/handlers/pay_form.inc, line 309
The base class for payment activities. All payment form classes should extend this.

Class

pay_form
@file The base class for payment activities. All payment form classes should extend this.

Code

function form_alter(&$form, &$form_state) {
  $group = $this
    ->handler();

  // Special handling for "amount-only" forms.
  if ($form_state['pay_form_type'] == 'amount') {
    $visible = array();
    foreach (element_children($form[$group]) as $key) {
      if (!in_array($key, array(
        'amount',
        'amount_other',
        'total',
      ))) {
        $form[$group][$key]['#access'] = FALSE;
      }

      // Keep track of any visible elements.
      if ($form[$group][$key]['#access'] !== FALSE) {
        $visible[] = $key;
      }

      // Change the 'action' to the ultimate destination for the form.
      $form['#action'] = url($this
        ->menu_path());

      // Change the 'method' to GET ...?
      $form['#method'] = 'get';
    }
  }

  // If only one field is visible, hide its label.
  if (isset($visible) && count($visible) == 1) {
    unset($form[$group][$visible[0]]['#title']);
  }
}