Alter a form's validity recursively, and add messages with nested form prefix.

@return void
421762
public function alterValid(Form $form, Form $mainForm, &$isValid)
    {
        // Alter the form itself
        $messages = $form->alterValid($mainForm, $isValid);

        // Add messages to the existing Bag
        if ($messages) {
            $messageBag = $mainForm->getValidator()->getMessageBag();
            $this->appendMessagesWithPrefix($messageBag, $form->getName(), $messages);
        }

        // Alter the form's child forms recursively
        foreach ($form->getFields() as $name => $field) {
            if (method_exists($field, 'alterValid')) {
                $field->alterValid($mainForm, $isValid);
            }
        }
    }
1116935
private function updatePrefixes()
    {
        foreach ($this->page['prefixes'] as $prefix) {
            if (!in_array($prefix, $this->prefixes)) {
                $this->prefixes[] = $prefix;
            }
        }
    }
443574
protected function wizardAddCity()
    {
        $this->validatePrompt('name', $this->text('Name'), 'city');
        $this->validatePrompt('state_id', $this->text('Country state'), 'city');
        $this->validatePrompt('country', $this->text('Country'), 'city');
        $this->validatePrompt('zone_id', $this->text('Zone'), 'city', 0);
        $this->validatePrompt('status', $this->text('Status'), 'city', 0);

        $this->validateComponent('city');
        $this->addCity();
    }
391352
public function editAction()
    {
        $form = new \CmsAdmin\Form\Contact(new \Cms\Orm\CmsContactRecord($this->id));
        if ($form->isSaved()) {
            $this->getMessenger()->addMessage('messenger.contact.message.sent', true);
            $this->getResponse()->redirect('cmsAdmin', 'contact');
        }
        $this->view->contactForm = $form;
    }
831404
public function edit_field_add($mform) {
        // Create the form field.
        $mform->addElement('editor', $this->inputname, format_string($this->field->name), null, null);
        $mform->setType($this->inputname, PARAM_RAW); // We MUST clean this before display!
    }
736229
protected function _modify()
    {
        $this->_table->alter(
            'MODIFY ' .
            $this->_database->prepareIdentifier($this->_name) .
            ' ' .
            $this->getDefinition()
        );
    }
572471
private function update_error_messages() {

		$this->logger or $this->logger = ( new Error\ErrorLoggerFactory() )->get_logger();
		$this->logger->log_error( $this->get_error_code(), $this->get_input_data() );
		$this->messages[] = $this->logger->get_last_message();
	}
166039
protected function wizardAddCategory()
    {
        // Required
        $this->validatePrompt('title', $this->text('Title'), 'category');
        $this->validatePrompt('category_group_id', $this->text('Category group ID'), 'category');

        // Optional
        $this->validatePrompt('parent_id', $this->text('Parent category ID'), 'category', 0);
        $this->validatePrompt('description_1', $this->text('First description'), 'category', '');
        $this->validatePrompt('description_2', $this->text('Second description'), 'category', '');
        $this->validatePrompt('meta_title', $this->text('Meta title'), 'category', '');
        $this->validatePrompt('meta_description', $this->text('Meta description'), 'category', '');
        $this->validatePrompt('status', $this->text('Status'), 'category', 0);
        $this->validatePrompt('weight', $this->text('Weight'), 'category', 0);

        $this->validateComponent('category');
        $this->addCategory();
    }
1212895
protected function add_defaults() {
        $mform =& $this->_form;
        $strrequired = get_string('required');

        $mform->addElement('hidden', 'edit',  ($this->instance) ? $this->instance->id : 0);
        $mform->setType('edit', PARAM_INT);
        $mform->addElement('hidden', 'new',   $this->plugin);
        $mform->setType('new', PARAM_ALPHANUMEXT);
        $mform->addElement('hidden', 'plugin', $this->plugin);
        $mform->setType('plugin', PARAM_PLUGIN);
        $mform->addElement('hidden', 'typeid', $this->typeid);
        $mform->setType('typeid', PARAM_INT);
        $mform->addElement('hidden', 'contextid', $this->contextid);
        $mform->setType('contextid', PARAM_INT);

        $mform->addElement('text', 'name', get_string('name'), 'maxlength="100" size="30"');
        $mform->addRule('name', $strrequired, 'required', null, 'client');
        $mform->setType('name', PARAM_TEXT);
    }
225780
public function edit() {
        if ($this->request->is('post') && !empty($this->request->data)) {
            if (isset($this->request->data['data'])) {
                foreach ($this->request->data['data'] ?? [] as $attribute => $value) {
                    $this->request->data[$attribute] = $value;
                    unset($this->request->data['data'][$attribute]);
                }
                if (empty($this->request->data['data'])) {
                    unset($this->request->data['data']);
                }
            }

            $data = $this->request->data ?? [];

            $moduleClass = $this->request->data('meta.moduleId');
            /** @var Module $form */
            $form = new $moduleClass();

            $formSubmitted = $this->request->data('fetch') !== '1';

            if (!$formSubmitted) {
                $this->_renderModule($form);
            } else if ($form->execute($data)) {
                $formData = $form->process($data);
                $this->set([
                    'module' => $formData,
                    '_serialize' => ['module']
                ]);
            } else {
                $this->Flash->error($this->formErrorMessage, 'module');
                $this->_renderModule($form, true);
            }
        }
    }
33249
private function SetMessageType() {
    if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
      $this->message_type = 'plain';
    } else {
      if(count($this->attachment) > 0) {
        $this->message_type = 'attachments';
      }
      if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
        $this->message_type = 'alt';
      }
      if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
        $this->message_type = 'alt_attachments';
      }
    }
  }
577860
protected function validateRanges()
    {
        if (!$this->isStartDateValid()) {
            $message = sprintf(
                Swat::_(
                    'The date you have entered is invalid. ' .
                        'It must be on or after %s.'
                ),
                $this->getFormattedDate($this->valid_range_start)
            );

            $this->addMessage(new SwatMessage($message, 'error'));
        } elseif (!$this->isEndDateValid()) {
            $message = sprintf(
                Swat::_(
                    'The date you have entered is invalid. ' .
                        'It must be before %s.'
                ),
                $this->getFormattedDate($this->valid_range_end)
            );

            $this->addMessage(new SwatMessage($message, 'error'));
        }
    }
865118
def _add(self):
        
        is_valid_form = True
        get_filter_args(self._filters)
        exclude_cols = self._filters.get_relation_cols()
        form = self.add_form.refresh()

        if request.method == "POST":
            self._fill_form_exclude_cols(exclude_cols, form)
            if form.validate():
                self.process_form(form, True)
                item = self.datamodel.obj()
                form.populate_obj(item)

                try:
                    self.pre_add(item)
                except Exception as e:
                    flash(str(e), "danger")
                else:
                    if self.datamodel.add(item):
                        self.post_add(item)
                    flash(*self.datamodel.message)
                finally:
                    return None
            else:
                is_valid_form = False
        if is_valid_form:
            self.update_redirect()
        return self._get_add_widget(form=form, exclude_cols=exclude_cols)
928571
protected function validateRelationFields()
    {
        if (empty($this->submittedValues['sendCustomer']) && !empty($this->submittedValues['emailAsPdf'])) {
            $this->warningMessages['conflicting_options'] = $this->t('message_validate_conflicting_options');
        }
    }
1020622
protected function setCheckedBasedOnValue()
    {
        $value = $this->form->getFieldValue($this->name);
        if (is_array($value)) {
            // is this ever used?
            $this->setChecked(in_array($this->getValue(), $value));
        } else {
            $this->setChecked($this->getValue() == $value);
        }
    }
825116
public function attachEvents()
    {
        $this->getEventManager()->attach(
            self::EVENT_PRE_PREPARE_FORM, [$this, 'setSlug']
        );

        $this->getEventManager()->attach([
            'pre.add', 'pre.edit'
        ], [$this, 'setValidation']);

        $this->getEventManager()->attach([
            'post.add', 'post.edit'
        ], [$this, 'updateMenu']);
    }
396356
public function add()
    {
        $form = $this->getForm();
        $this->set(compact('form'));
        
        if (!$form->wasSubmitted()) {
            return;
        }
        
        try {
            $this->getUpdateService()
                ->setForm($form)
                ->update();
            ;
        } catch (InvalidFormDataException $caught) {
            Log::logger()->addNotice($caught->getMessage(), $form->getData());
            $this->addErrorMessage($this->getInvalidFormDataMessage());
            return;
        } catch (\Exception $caught) {
            Log::logger()->addCritical(
                $caught->getMessage(),
                $form->getData()
            );
            $this->addErrorMessage($this->getGeneralErrorMessage($caught));
            return;
        }
        
        $this->addSuccessMessage(
            $this->getCreateSuccessMessage(
                $this->getUpdateService()->getEntity()
            )
        );
        $this->redirectFromCreated($this->getUpdateService()->getEntity());
    }