2 namespace wcf\acp\form
;
3 use wcf\data\person\PersonAction
;
4 use wcf\form\AbstractForm
;
5 use wcf\system\exception\UserInputException
;
7 use wcf\util\StringUtil
;
10 * Shows the form to create a new person.
12 * @author Matthias Schmidt
13 * @copyright 2001-2019 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\Acp\Form
17 class PersonAddForm
extends AbstractForm
{
21 public $activeMenuItem = 'wcf.acp.menu.link.person.add';
24 * first name of the person
27 public $firstName = '';
30 * last name of the person
33 public $lastName = '';
38 public $neededPermissions = ['admin.content.canManagePeople'];
43 public function assignVariables() {
44 parent
::assignVariables();
46 WCF
::getTPL()->assign([
48 'firstName' => $this->firstName
,
49 'lastName' => $this->lastName
56 public function readFormParameters() {
57 parent
::readFormParameters();
59 if (isset($_POST['firstName'])) $this->firstName
= StringUtil
::trim($_POST['firstName']);
60 if (isset($_POST['lastName'])) $this->lastName
= StringUtil
::trim($_POST['lastName']);
66 public function save() {
69 $this->objectAction
= new PersonAction([], 'create', [
70 'data' => array_merge($this->additionalFields
, [
71 'firstName' => $this->firstName
,
72 'lastName' => $this->lastName
75 $this->objectAction
->executeAction();
80 $this->firstName
= '';
83 // show success message
84 WCF
::getTPL()->assign('success', true);
90 public function validate() {
93 // validate first name
94 if (empty($this->firstName
)) {
95 throw new UserInputException('firstName');
97 if (mb_strlen($this->firstName
) > 255) {
98 throw new UserInputException('firstName', 'tooLong');
101 // validate last name
102 if (empty($this->lastName
)) {
103 throw new UserInputException('lastName');
105 if (mb_strlen($this->lastName
) > 255) {
106 throw new UserInputException('lastName', 'tooLong');