You are here

function panels_mini_edit_form_validate in Panels 6.2

Same name and namespace in other branches
  1. 5.2 panels_mini/panels_mini.module \panels_mini_edit_form_validate()

Validate submission of the mini panel edit form.

File

panels_mini/panels_mini.admin.inc, line 491
Administrative items for the panels mini module.

Code

function panels_mini_edit_form_validate($form, &$form_state) {

  // Test uniqueness of name:
  if (!$form_state['values']['name']) {
    form_error($form['left']['settings']['name'], t('Panel mini name is required.'));
  }
  else {
    if (preg_match("/[^A-Za-z0-9_]/", $form_state['values']['name'])) {
      form_error($form['left']['settings']['name'], t('Name must be alphanumeric or underscores only.'));
    }
    else {
      if (preg_match("/[^A-Za-z0-9 ]/", $form_state['values']['category'])) {
        form_error($form['left']['settings']['category'], t('Categories may contain only alphanumerics or spaces.'));
      }
      else {
        $query = "SELECT pid FROM {panels_mini} WHERE name = '%s'";
        if (!empty($form_state['values']['pid']) && is_numeric($form_state['values']['pid'])) {
          $query .= ' AND pid != ' . $form_state['values']['pid'];
        }
        if (db_result(db_query($query, $form_state['values']['name']))) {
          form_error($form['left']['settings']['name'], t('Panel name must be unique.'));
        }
      }
    }
  }
}