addElement('autocomplete', 'toUserId', [ 'label' => 'To', 'dataUrl' => $this->getAutocompleteUrl(), 'required' => true, 'placeholder' => 'Member Autocomplete', 'validators' => [ ['Callback', true, [ 'callback' => UserModel::class . '::likeToReceivePm', 'messages' => 'This member don\'t like to receive private messages', ]], ['Compare', true, [ 'operator' => '!=', 'rightValue' => $this->getLoggedInUserId(), 'messages' => 'You can\'t send a message to yourself', ]], ], ]); /** @var \Qs_Form_Element_Autocomplete $toUserId */ if ($this->getUserName() && ($toUserId = $this->getElement('toUserId'))) { $toUserId->setTitle($this->getUserName()); } $this->addElement('text', 'subject', ['label' => 'Subject', 'required' => true]); $this->addElement('textarea', 'body', ['label' => 'Body', 'required' => true, 'rows' => 20]); return $this; } public function addButtons() { parent::addButtons(); $this->getElement('btnSubmit')->setLabel('Send'); return $this; } public function getAutocompleteUrl() { return $this->_autocompleteUrl; } public function setAutocompleteUrl($url) { $this->_autocompleteUrl = $url; return $this; } public function getUserName() { return $this->_userName; } public function setUserName($userName) { $this->_userName = $userName; return $this; } public function getLoggedInUserId() { return $this->_loggedInUserId; } public function setLoggedInUserId($loggedInUserId) { $this->_loggedInUserId = $loggedInUserId; return $this; } }