You are here

function commerce_purchase_order_submit_form_validate in Commerce Purchase Order 7

Payment method callback: submit form validation.

File

./commerce_purchase_order.module, line 152
Provides an example payment method for Drupal Commerce for testing and development.

Code

function commerce_purchase_order_submit_form_validate($payment_method, $pane_form, $pane_values, $order, $form_parents = array()) {

  // If user did not set default value, set it to 0.
  $po_length = empty($payment_method['settings']) ? 0 : $payment_method['settings']['commerce_purchase_order_length'];

  // Automatically return true if $po_length is set to 0.
  if ($po_length == 0) {
    return TRUE;
  }

  // Throw an error if a long enough number was not provided.
  if (strlen($pane_values['po_number']) < $po_length) {
    form_set_error(implode('][', array_merge($form_parents, array(
      'name',
    ))), t('You must enter a purchase order number at least !po_length characters long.', array(
      '!po_length' => $po_length,
    )));

    // Even though the form error is enough to stop the submission of the form,
    // it's not enough to stop it from a Commerce standpoint because of the
    // combined validation / submission going on per-pane in the checkout form.
    return FALSE;
  }
}