You are here

function uc_dropdown_attributes_validate in Dropdown Attributes 6

Handles the validation of required fields.

1 string reference to 'uc_dropdown_attributes_validate'
uc_dropdown_attributes_form_alter in ./uc_dropdown_attributes.module
Implements hook_form_alter().

File

./uc_dropdown_attributes.module, line 238
Show/hide attributes based on the values of other attributes.

Code

function uc_dropdown_attributes_validate($form, &$form_state) {
  if (preg_match('/^uc-product-kit-add-to-cart-form.*/', $form['#id'])) {
    foreach ($form['products'] as $key => $value) {
      if (is_numeric($key)) {
        $sql = 'SELECT aid, parent_aid, parent_values FROM {uc_dropdown_attributes}
          WHERE required=1 AND nid=%d';
        $result = db_query($sql, $key);
        while ($item = db_fetch_object($result)) {
          $values = unserialize($item->parent_values);
          if (is_array($form_state['values']['products'][$key]['attributes'][$item->parent_aid])) {
            if (count(array_intersect($values, $form_state['values']['products'][$key]['attributes'][$item->parent_aid])) > 0) {
              uc_dropdown_attributes_attribute_value_check($item->aid, $form_state['values']['products'][$key]['attributes'][$item->aid]);
            }
          }
          else {
            if (in_array($form_state['values']['products'][$key]['attributes'][$item->parent_aid], $values)) {
              uc_dropdown_attributes_attribute_value_check($item->aid, $form_state['values']['products'][$key]['attributes'][$item->aid]);
            }
          }
        }
      }
    }
  }
  else {
    $sql = 'SELECT aid, parent_aid, parent_values FROM {uc_dropdown_attributes}
      WHERE required=1 AND nid=%d';
    $result = db_query($sql, $form_state['values']['nid']);
    while ($item = db_fetch_object($result)) {
      $values = unserialize($item->parent_values);
      if (is_array($form_state['values']['attributes'][$item->parent_aid])) {
        if (count(array_intersect($values, $form_state['values']['attributes'][$item->parent_aid])) > 0) {
          uc_dropdown_attributes_attribute_value_check($item->aid, $form_state['values']['attributes'][$item->aid]);
        }
      }
      else {
        if (in_array($form_state['values']['attributes'][$item->parent_aid], $values)) {
          uc_dropdown_attributes_attribute_value_check($item->aid, $form_state['values']['attributes'][$item->aid]);
        }
      }
    }
  }
}