existsGroupName() public static method

Check if a group name exists.
public static existsGroupName ( string $groupName, integer $id = null ) : boolean
$groupName string Group name.
$id integer Group id to ignore.
return boolean
Example #1
0
 /**
  * Validate the form.
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // get field
         /** @var $txtName \SpoonFormText */
         $txtName = $this->frm->getField('name');
         // name filled in?
         if ($txtName->isFilled(BL::getError('NameIsRequired'))) {
             // name exists?
             if (BackendProfilesModel::existsGroupName($txtName->getValue())) {
                 // set error
                 $txtName->addError(BL::getError('GroupNameExists'));
             }
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $values['name'] = $txtName->getValue();
             // insert values
             $id = BackendProfilesModel::insertGroup($values);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_group', array('item' => $values));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Groups') . '&report=group-added&var=' . rawurlencode($values['name']) . '&highlight=row-' . $id);
         }
     }
 }