You are here

function uc_roles_feature_form_validate in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_roles/uc_roles.module \uc_roles_feature_form_validate()
  2. 7.3 uc_roles/uc_roles.module \uc_roles_feature_form_validate()

File

uc_roles/uc_roles.module, line 644
Grants roles upon accepted payment of products

Code

function uc_roles_feature_form_validate($form_id, $form_values) {
  if ($form_values['uc_roles_granularity'] != 'never' && intval($form_values['uc_roles_qty']) < 1) {
    form_set_error('uc_roles_qty', t('The amount of time must be a positive integer.'));
  }
  if (empty($form_values['uc_roles_role'])) {
    form_set_error('uc_roles_role', t('You must have a role to assign. You may need to <a href="!role_url">create a new role</a> or perhaps <a href="!feature_url">set role assignment defaults</a>.', array(
      '!role_url' => url('admin/user/roles'),
      '!feature_url' => url('admin/store/settings/products/edit/features'),
    )));
  }
  if ($product_roles = db_fetch_object(db_query("SELECT * FROM {uc_roles_products} WHERE nid = %d AND model = '%s' AND rid = %d", $form_values['nid'], $form_values['uc_roles_model'], $form_values['uc_roles_role'])) && $form_values['pfid'] == 0) {
    form_set_error('uc_roles_role', t('The combination of model/SKU and role already exists for this product.'));
    form_set_error('uc_roles_model', t(' '));
  }
}