You are here

function commerce_cardonfile_update_form_validate in Commerce Card on File 7

Form validate handler: update stored card data.

File

includes/commerce_cardonfile.pages.inc, line 92
User page callbacks and forms for Commerce Card on File.

Code

function commerce_cardonfile_update_form_validate($form, &$form_state) {
  module_load_include('inc', 'commerce_payment', 'includes/commerce_payment.credit_card');

  // Ensure non-default values are valid numbers.
  if ($form_state['values']['credit_card']['number'] != $form['credit_card']['number']['#default_value']) {
    if (!commerce_payment_validate_credit_card_number($form_state['values']['credit_card']['number'])) {
      form_set_error('credit_card][number', t('The credit card number you entered is invalid.'));
    }
  }

  // Ensure the expiration date is not being updated to a past date.
  $exp_valid = commerce_payment_validate_credit_card_exp_date($form_state['values']['credit_card']['exp_month'], $form_state['values']['credit_card']['exp_year']);
  if ($exp_valid !== TRUE) {
    form_set_error('credit_card][exp_' . $exp_valid, t('You have specified an expired credit card.'));
  }
}