You are here

function pay_form::form_validate in Pay 7

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

Overrides pay::form_validate

File

includes/handlers/pay_form.inc, line 340
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_validate($form, &$form_state) {
  parent::form_validate($form, $form_state);
  $values = $this
    ->form_values($form_state);
  $group = $this
    ->handler();
  if ($this
    ->user_register()) {

    // Copy & overwrite form values so it looks like a user_registration form.
    $register_state = $form_state;
    $register_state['values'] = $values['register'];

    // Execute all of the user_registration form's submit handlers.
    $register = $form[$this
      ->handler()]['register'];
    form_execute_handlers('validate', $register, $register_state);

    // Copy any new $register_state values into $form_state.
    $form_state = array_merge($register_state, $form_state);
  }

  // Remove non-numeric characters from the total.
  $total = (double) preg_replace('/[^\\d\\.]/', '', $values['total']);

  // Confirm that the amount falls within our min/max settings.
  if ($total < $this->min_amount || $total > $this->max_amount) {
    $error = t('Please enter an amount between %min and %max', array(
      '%min' => $this->min_amount,
      '%max' => $this->max_amount,
    ));
    form_set_error('total', $error);
  }

  // If there is no total value per payment method, set the global total.
  foreach ($values['pay_method']['selected'] as $pmid => $status) {
    if (!$status) {
      continue;
    }
    $method_values = $values['pay_method'][$pmid];
    $method_values['pmid'] = $pmid;
    $method_element = $form[$group]['pay_method'][$pmid];
    if (!$method_values['total']) {
      form_set_value($method_element['total'], (double) $total, $form_state);
      $method_values['total'] = $total;
    }
    $pay_method = pay_method_load($method_values);
    $pay_method
      ->pay_method_validate($form, $form_state, $method_element);
  }
}