You are here

function commerce_registration_defer_form_validate in Commerce Registration 7.2

Validation callback for the registration deferral form.

File

modules/commerce_registration_defer/commerce_registration_defer.module, line 125
Module file for commerce_registration_defer.

Code

function commerce_registration_defer_form_validate($form, &$form_state) {
  $order = $form_state['build_info']['args'][1];
  $line_item_type = $form['actions']['line_item_type']['#value'];

  // Create the new line item.
  $line_item = commerce_line_item_new($line_item_type['type'], $order->order_id);

  // If this type specifies a valid add form callback function...
  if ($callback = commerce_line_item_type_callback($line_item_type, 'add_form_submit')) {

    // Allow the callback to alter data onto the line item to be saved and
    // to return an error message if something goes wrong.
    if ($error = $callback($line_item, $form, $form_state, $form)) {

      // Unfortunately we can't be certain of what the error is for so add it
      // to the whole form.
      form_set_error('', $error);
    }
    else {

      // Save the new line item and use it in the submit callback.
      $form_state['build_info']['new_line_item'] = $line_item;
    }
  }
}