Hello, I don't know how to get clicked buttons name using FormAPI. I added with a foreach all the online players to the UI, but i don't know what names got selected and submitted. Can you help?
send message to you for view what is returned in form why click in botton use: $player = your name; $player->sendMessage(print_r($data, 1)); Send your code to i view and send code to you
send me your code. The formapi returns values array $data use print_r($data, 1) to view value returned (name buttons )
Code: $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $form = $api->createCustomForm(function (Player $player, $data) { if ($data === null) { return; } if ($data == true) { $player->sendMessage("Hi This is the button: " . print_r($data, true)); } }); $form->setTitle("test"); $form->addLabel("select the players you want to send a message to"); foreach ($this->getServer()->getOnlinePlayers() as $online) { if ($online !== $player) { $form->addToggle($online->getName()); } }
It says: array [ 0 => 1 => 1 ] it shows up only the bool to tell me if the response is true or not but it doesnt show up any name
Dropdown return value bool: 0 or null for false (disabled) 1 for true (enabled) Test my code: PHP: public $names = [];$api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $form = $api->createCustomForm(function (Player $player, $data) { if ($data === null) { return; }$num = 0;foreach($data as $n){if($num != 0 and isset($this->names[$player->getName()]) and $n == 1){$playerToMessage = $this->names[$player->getName()][$num];/// code for player$num++;}}unset($this->names[$player->getName()]); if ($data == true) { $player->sendMessage("Hi This is the button: " . print_r($data, true)); } }); $form->setTitle("test"); $form->addLabel("select the players you want to send a message to");$num = 1; foreach ($this->getServer()->getOnlinePlayers() as $online) { if ($online !== $player) { $form->addToggle($online->getName()); $this->names[$player->getName()][$num] = $online;$num++; } } Good luck
I have no way to test but I will make the code send some messages and you send me to identify the error PHP: $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $form = $api->createCustomForm(function (Player $player, $data) { if ($data === null) { return; }$num = 0;foreach($data as $n){if($num != 0 and $n == 1){$playerToMessage = $this->names[$player->getName()][$num];/// code for player$num++;}}$player->sendMessage(print_r($this->names[$player->getName()], 1));unset($this->names[$player->getName()]); if ($data == true) { $player->sendMessage("Hi This is the button: " . print_r($data, true)); } }); $form->setTitle("test"); $form->addLabel("select the players you want to send a message to");$num = 1; foreach ($this->getServer()->getOnlinePlayers() as $online) { if ($online !== $player) { $form->addToggle($online->getName()); $this->names[$player->getName()][$num] = $online;$num++; } }