Backend\Modules\Groups\Actions\Add::validateForm PHP Method

validateForm() private method

Validate the form
private validateForm ( )
    private function validateForm()
    {
        if ($this->frm->isSubmitted()) {
            $bundledActionPermissions = array();
            // cleanup the submitted fields, ignore fields that were added by hackers
            $this->frm->cleanupFields();
            // get fields
            $nameField = $this->frm->getField('name');
            foreach ($this->modules as $module) {
                // loop through actions
                foreach ($this->actions[$module['value']] as $action) {
                    // collect permissions if not bundled
                    if (!array_key_exists('group', $action)) {
                        $actionPermissions[] = $this->frm->getField('actions_' . $module['label'] . '_' . $action['label']);
                    }
                }
                // loop through bundled actions
                foreach ($this->actionGroups as $key => $group) {
                    // loop through all fields
                    foreach ($this->frm->getFields() as $field) {
                        // field exists?
                        if ($field->getName() == 'actions_' . $module['label'] . '_' . 'Group_' . \SpoonFilter::ucfirst($key)) {
                            // add to bundled actions
                            $bundledActionPermissions[] = $this->frm->getField('actions_' . $module['label'] . '_' . 'Group_' . \SpoonFilter::ucfirst($key));
                        }
                    }
                }
            }
            // loop through widgets and collect presets
            $widgetPresets = array();
            foreach ($this->widgets as $widget) {
                $widgetPresets[] = $this->frm->getField('widgets_' . $widget['checkbox_name']);
            }
            // validate fields
            $nameField->isFilled(BL::err('NameIsRequired'));
            // group already exists?
            if (BackendGroupsModel::alreadyExists($nameField->getValue())) {
                $nameField->setError(BL::err('GroupAlreadyExists'));
            }
            // no errors?
            if ($this->frm->isCorrect()) {
                // insert widgets
                $group = $this->insertWidgets($widgetPresets);
                // assign id
                $this->id = $group['id'];
                // insert permissions
                $this->insertPermissions($actionPermissions, $bundledActionPermissions);
                // trigger event
                BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $group));
                // everything is saved, so redirect to the overview
                $this->redirect(BackendModel::createURLForAction('Index') . '&report=added&var=' . rawurlencode($group['name']) . '&highlight=row-' . $group['id']);
            }
        }
    }