octobercms/october · error · ValidationException

Name can contain only digits, Latin letters and the…

Error message

Name can contain only digits, Latin letters and the following symbols: _-

What it means

Format validation in index_onCreate: the desired theme directory name fails the ^[a-z0-9_-]+$/i pattern (contains spaces, dots or special characters), so the directory name is rejected before the theme folder is created.

Solutions

  1. Use only letters, digits, underscores and dashes in the directory name
  2. Let the UI slugify the name automatically
  3. Avoid locale-specific characters in dir_name
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/cms/controllers/Themes.php:204 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/44c7df4f1ada940b. Report an issue: GitHub.

Appendix: source

Thrown at modules/cms/controllers/Themes.php:204

    public function index_onCreate()
    {
        if (!BackendAuth::userHasAccess('cms.themes.create')) {
            throw new ForbiddenException;
        }

        $widget = $this->makeCreateFormWidget();
        $data = $widget->getSaveData();
        $newDirName = trim($data['dir_name'] ?? '');
        $destinationPath = themes_path().'/'.$newDirName;

        $data = array_except($data, 'dir_name');

        if (!strlen(trim($data['name'] ?? ''))) {
            throw new ValidationException(['name' => __('Please specify a name for the theme.')]);
        }

        if (!preg_match('/^[a-z0-9\_\-]+$/i', $newDirName)) {
            throw new ValidationException(['dir_name' => __('Name can contain only digits, Latin letters and the following symbols: _-')]);
        }

        if (File::isDirectory($destinationPath)) {
            throw new ValidationException(['dir_name' => __('Desired theme directory already exists.')]);
        }

        File::makeDirectory($destinationPath);
        File::makeDirectory($destinationPath.'/assets');
        File::makeDirectory($destinationPath.'/content');
        File::makeDirectory($destinationPath.'/layouts');
        File::makeDirectory($destinationPath.'/pages');
        File::makeDirectory($destinationPath.'/partials');
        File::put($destinationPath.'/theme.yaml', '');

        $theme = CmsTheme::load($newDirName);
        $theme->writeConfig($data);

        Flash::success(__('Theme Created!'));

View on GitHub (pinned to b608633a7e)