Skip to content

Modal Form

VennV edited this page Jul 29, 2024 · 2 revisions

According to the introduction at HOME, this is the second menu type of the three, and is also the easiest menu to make but unlike NORMAL_FORM, MODAL_FORM only has 2 functions (image is not supported), Besides that, the code has not changed at all

You can refer to here:

Example Code:

use pocketmine\player\Player;

use venndev\vformoopapi\Form;
use venndev\vformoopapi\attributes\VForm;
use venndev\vformoopapi\attributes\modal\VButton;
use vennvdev\vformoopapi\utils\TypeForm;

#[VForm(
  title: "Your Menu Title",
  type: TypeForm::MODAL_FORM,
  content: "Your Menu Content"
)]
final class YourClass extends Form{
  
  public function __construct(Player $player){
   parent::__construct($player);
   $this->setContent("This is example for Modal Form"); //<-- This is the content at 'content' before the class
  }

  #[VButton(
    text: "Your Text" //Button1   
  )]
  public function YourTextFunction(Player $player, mixed $data) : void{
   $player->sendMessage("You have pressed button 1");
  }

  #[VButton(
    text: "Your Text 2" //Button2
  )]
  public function YourFunction(Player $player, mixed $data) : void{
   $player->sendMessage("You pressed button 2!");
  }
  
    protected function onClose(Player $player): void
    {
        $player->sendMessage("You have closed the form");
    }

    // This method is called when the form is submitted
    protected function onCompletion(Player $player, mixed $data): void
    {
        // TODO: Implement onCompletion() method.
    }
}
  • NOTE:
  • You need to do something like Example Code for the menu to work
  • #[VButton()] => Create button for menu
  • #[VForm()] => Create new menu
Clone this wiki locally