You are here

function acquia_lift_personalize_campaign_wizard_goals_validate in Acquia Lift Connector 7.2

Validation function for goals form.

File

./acquia_lift.admin.wizard.inc, line 1852
acquia_lift.admin.wizard.inc Functions specific to the Acquia Lift alteration of the campaign creation wizard.

Code

function acquia_lift_personalize_campaign_wizard_goals_validate(&$form, &$form_state) {

  // Make sure that each action is only set once per campaign.
  // Note that the error message is only shown once as we only have access
  // to the action machine name for display and it would be too repetitive to
  // to show the same message over and over.
  $used_actions = array();
  if (!empty($form_state['values']['goals']['all_goals'])) {
    foreach ($form_state['values']['goals']['all_goals'] as $delta => $goal) {
      if (empty($goal['action_name'])) {
        continue;
      }
      if (array_search($goal['action_name'], $used_actions) !== FALSE) {
        form_set_error('goals[all_goals][' . $delta . '][action_name]', t('Actions can only be used once per personalization.'));
        return;
      }
      else {
        $used_actions[] = $goal['action_name'];
      }
    }
  }
  if (!empty($form_state['new_goals'])) {
    foreach ($form_state['new_goals'] as $delta => $type) {
      if ($type == 'page') {

        // Validate the page input via plugin validator.
        ctools_include('plugins');
        if ($class = ctools_plugin_load_class('visitor_actions', 'actionable_element', 'page', 'handler')) {

          // @todo Any validation errors shown will not be shown with the
          // correct field highlighted, or at all if limit_validation_errors
          // is used.
          call_user_func_array(array(
            $class,
            'validate',
          ), array(
            $form_state['values']['goals']['new'][$delta]['details'],
          ));
        }
        continue;
      }
      if ($type !== 'existing') {
        continue;
      }
      $new_action_name = $form_state['values']['goals']['new'][$delta]['details']['action_name'];
      if (empty($new_action_name)) {
        continue;
      }
      if (array_search($new_action_name, $used_actions) !== FALSE) {
        form_set_error('goals[new][' . $delta . '][details][action_name]', t('Actions can only be used once per personalization.'));
        return;
      }
      $used_actions[] = $new_action_name;
    }
  }
}