Skip to main content

Modal Form

To make a Modal Form we need to add the "use" statement.

use jojoe77777\FormAPI\ModalForm;

Now lets make a function to add our form in it.

public function testForm($player) 
{
//This is where we will add our form.
}

In the function we will add our form:

public function testForm($player)
{
$form = new ModalForm(function(Player $player, $data){
if($data === true){

return true;
}
return;
});

$player->sendForm($form); //This sends it to the player
}

Title

Let us set the title of the form.

public function testForm($player)
{
$form = new ModalForm(function(Player $player, $data){
if($data === true){

return true;
}
return;
});

//This sets the title of the form
$form->setTitle("Your Title");

$player->sendForm($form);
}

modalform-title

Description

Let us add a description to the form.

public function testForm($player)
{
$form = new ModalForm(function(Player $player, $data){
if($data === true){

return true;
}
return;
});

$form->setTitle("Your Title");
//This adds a description to the form
$form->setContent("Your description");
$player->sendForm($form);
}

modalform-description

Button

Let us set the buttons to the form.

public function testForm($player)
{
$form = new ModalForm(function(Player $player, $data){
if($data === true){

return true;
}
return;
});

$form->setTitle("Your Title");
$form->setContent("Your description");
//This sets the buttons
$form->setButton1("First choice");
$form->setButton2("Second choice");
$player->sendForm($form);
}

modalform-buttons