You are here

function homebox_check_name in Homebox 7.3

Same name and namespace in other branches
  1. 6.3 homebox.module \homebox_check_name()
  2. 6.2 homebox.module \homebox_check_name()
  3. 7.2 homebox.module \homebox_check_name()

Validation helper function for page name

Parameters

$name: The name to be tested for the page

$element: Optional, the form element identifier to throw form errors

Return value

TRUE if name is valid to use, otherwise, FALSE.

2 calls to homebox_check_name()
homebox_admin_page_validate in ./homebox.admin.inc
Validation functino for the admin page form.
homebox_check_page_object in ./homebox.module
Validation helper to check a page object

File

./homebox.module, line 984
Homebox main file, takes care of global functions settings constants, etc.

Code

function homebox_check_name($name, $element = NULL) {

  // Ensure name fits the rules:
  if (preg_match('/[^a-z0-9_]/', $name)) {
    if ($element) {
      form_set_error($element, t('Machine name must be lowercase alphanumeric or underscores only.'));
    }
    return FALSE;
  }

  // Check for name dupes
  if ((bool) db_query('SELECT 1 FROM {homebox_pages} WHERE name = :name', array(
    ':name' => $name,
  ))
    ->fetchField()) {
    if ($element) {
      form_set_error($element, t('The page name %name already exists. Please choose another page name.', array(
        '%name' => $name,
      )));
    }
    return FALSE;
  }
  return TRUE;
}