You are here

function pay_form::form in Pay 7

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

Overrides pay::form

File

includes/handlers/pay_form.inc, line 256
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(&$form, &$form_state) {
  parent::form($form, $form_state);
  $group = $this
    ->handler();

  // If an amount-only form was submitted, get the amount from $_GET.
  if (isset($_GET[$group]['amount'])) {
    $this
      ->set_amount($_GET[$group]['amount']);
  }
  $form[$group]['total'] = array(
    '#type' => 'textfield',
    '#size' => 6,
    '#title' => t('Amount'),
  );

  // Include a user registration form, if necessary.
  if ($this
    ->user_register()) {
    $required = $this
      ->user_register() == 'required';
    $register = drupal_retrieve_form('user_register', $form_state);
    drupal_prepare_form('user_register', $register, $form_state);
    $exclude = array(
      'form_id',
      '#build_id',
      '#id',
      '#method',
      '#action',
      'submit',
    );
    foreach ($register as $key => $value) {
      if (!in_array($key, $exclude)) {
        if ($key[0] != '#' && is_array($value)) {

          // Manage 'required' if the account registration isn't.
          if (!$required && isset($value['#required'])) {
            $value['#user_register_required'] = $value['#required'];
            unset($value['#required']);
          }

          // Set #parents so that the value can be located by pay.
          $value['#parents'] = array(
            $group,
            'register',
            $key,
          );
        }

        // Add the registration form's field to a user registration element.
        $form[$group]['register'][$key] = $value;
      }
    }
  }

  // Add a payment method selection form.
  $this
    ->pay_method_form($form, $form_state);
  $form[$group]['notes'] = array(
    '#type' => 'textarea',
    '#title' => $this->notes_title,
    '#description' => $this->notes_description,
  );
}