private function validateForm()
{
if ($this->frm->isSubmitted()) {
$this->frm->cleanupFields();
// redefine fields
$txtName = $this->frm->getField('name');
$txtValue = $this->frm->getField('value');
// name checks
if ($txtName->isFilled(BL::err('FieldIsRequired'))) {
// allowed regex (a-z and 0-9)
if ($txtName->isValidAgainstRegexp('|^([a-z0-9])+$|i', BL::err('InvalidName'))) {
// first letter does not seem to be a capital one
if (!in_array(mb_substr($txtName->getValue(), 0, 1), range('A', 'Z'))) {
$txtName->setError(BL::err('InvalidName'));
} else {
// this name already exists in this language
if (BackendLocaleModel::existsByName($txtName->getValue(), $this->frm->getField('type')->getValue(), $this->frm->getField('module')->getValue(), $this->frm->getField('language')->getValue(), $this->frm->getField('application')->getValue())) {
$txtName->setError(BL::err('AlreadyExists'));
}
}
}
}
// value checks
if ($txtValue->isFilled(BL::err('FieldIsRequired'))) {
// in case this is a 'act' type, there are special rules concerning possible values
if ($this->frm->getField('type')->getValue() == 'act') {
if (rawurlencode($txtValue->getValue()) != CommonUri::getUrl($txtValue->getValue())) {
$txtValue->addError(BL::err('InvalidValue'));
}
}
}
// module should be 'core' for any other application than backend
if ($this->frm->getField('application')->getValue() != 'Backend' && $this->frm->getField('module')->getValue() != 'Core') {
$this->frm->getField('module')->setError(BL::err('ModuleHasToBeCore'));
}
if ($this->frm->isCorrect()) {
// build item
$item['user_id'] = BackendAuthentication::getUser()->getUserId();
$item['language'] = $this->frm->getField('language')->getValue();
$item['application'] = $this->frm->getField('application')->getValue();
$item['module'] = $this->frm->getField('module')->getValue();
$item['type'] = $this->frm->getField('type')->getValue();
$item['name'] = $this->frm->getField('name')->getValue();
$item['value'] = $this->frm->getField('value')->getValue();
$item['edited_on'] = BackendModel::getUTCDate();
// update item
$item['id'] = BackendLocaleModel::insert($item);
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
// everything is saved, so redirect to the overview
$this->redirect(BackendModel::createURLForAction('Index', null, null, null) . '&report=added&var=' . rawurlencode($item['name']) . '&highlight=row-' . $item['id'] . $this->filterQuery);
}
}
}