You are here

function _install_settings_form_validate in Drupal 5

Same name and namespace in other branches
  1. 6 install.php \_install_settings_form_validate()

Helper function for install_settings_validate.

2 calls to _install_settings_form_validate()
install_settings_form_validate in ./install.php
Form API validate for install_settings form.
install_verify_settings in ./install.php
Verify existing settings.php

File

./install.php, line 315

Code

function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_port, $db_path, $settings_file, $form = NULL) {
  global $db_url;

  // Check for default username/password
  if ($db_user == 'username' && $db_pass == 'password') {
    form_set_error('db_user', st('You have configured @drupal to use the default username and password. This is not allowed for security reasons.', array(
      '@drupal' => drupal_install_profile_name(),
    )));
  }

  // Verify the table prefix
  if (!empty($db_prefix) && is_string($db_prefix) && !preg_match('/^[A-Za-z0-9_]+$/', $db_prefix)) {
    form_set_error('db_prefix', st('The database table prefix you have entered, %db_prefix, is invalid. The table prefix can only contain alphanumeric characters or underscores.', array(
      '%db_prefix' => $db_prefix,
    )), 'error');
  }
  if (!empty($db_port) && !is_numeric($db_port)) {
    form_set_error('db_port', st('Database port must be a number.'));
  }

  // Check database type
  if (!isset($form)) {
    $_db_url = is_array($db_url) ? $db_url['default'] : $db_url;
    $db_type = substr($_db_url, 0, strpos($_db_url, '://'));
  }
  $databases = drupal_detect_database_types();
  if (!in_array($db_type, $databases)) {
    form_set_error('db_type', st("In your %settings_file file you have configured @drupal to use a %db_type server, however your PHP installation currently does not support this database type.", array(
      '%settings_file' => $settings_file,
      '@drupal' => drupal_install_profile_name(),
      '%db_type' => $db_type,
    )));
  }
  else {

    // Verify
    $db_url = $db_type . '://' . urlencode($db_user) . ($db_pass ? ':' . urlencode($db_pass) : '') . '@' . ($db_host ? urlencode($db_host) : 'localhost') . ($db_port ? ":{$db_port}" : '') . '/' . urlencode($db_path);
    if (isset($form)) {
      form_set_value($form['_db_url'], $db_url);
    }
    $success = array();
    $function = 'drupal_test_' . $db_type;
    if (!$function($db_url, $success)) {
      if (isset($success['CONNECT'])) {
        form_set_error('db_type', st('In order for Drupal to work and to proceed with the installation process you must resolve all permission issues reported above. We were able to verify that we have permission for the following commands: %commands. For more help with configuring your database server, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what any of this means you should probably contact your hosting provider.', array(
          '%commands' => implode($success, ', '),
        )));
      }
      else {
        form_set_error('db_type', '');
      }
    }
  }
}