You are here

public function wf_crm_webform_postprocess::validate in Webform CiviCRM Integration 7.4

Same name and namespace in other branches
  1. 7.5 includes/wf_crm_webform_postprocess.inc \wf_crm_webform_postprocess::validate()

Called after a webform is submitted Or, for a multipage form, called after each page

_state (reference)

Parameters

array $form:

File

includes/wf_crm_webform_postprocess.inc, line 71

Class

wf_crm_webform_postprocess

Code

public function validate($form, &$form_state) {
  $this->form = $form;
  $this->form_state =& $form_state;
  $this->rawValues = _webform_client_form_submit_flatten($this->node, wf_crm_aval($this->form_state, 'values:submitted'));
  $this->crmValues = wf_crm_enabled_fields($this->node, $this->rawValues);

  // Even though this object is destroyed between page submissions, this trick allows us to persist some data - see below
  $this->ent = wf_crm_aval($form_state, 'civicrm:ent', array());
  $this
    ->hiddenFieldValidation();
  $this
    ->validateThisPage($this->form['submitted']);
  if (!empty($this->data['participant']) && !empty($this->data['participant_reg_type'])) {
    $this
      ->loadMultiPageData();
    $this
      ->validateParticipants();
  }

  // Process live contribution. If the transaction is unsuccessful it will trigger a form validation error.
  if ($this->contribution_page) {

    // Ensure contribution js is still loaded if the form has to refresh
    $this
      ->addPaymentJs();
    $this
      ->loadMultiPageData();
    if ($this
      ->tallyLineItems()) {
      if ($this
        ->isLivePaymentProcessor() && $this
        ->isPaymentPage() && !form_get_errors()) {
        if ($this
          ->validateBillingFields()) {
          if ($this
            ->createBillingContact()) {
            $this
              ->submitLivePayment();
          }
        }
      }
    }
  }

  // Even though this object is destroyed between page submissions, this trick allows us to persist some data - see above
  $form_state['civicrm']['ent'] = $this->ent;
  $form_state['civicrm']['line_items'] = $this->line_items;
}