xanderid/pocketform

PocketForm is a simple forms Library for PocketMine-MP.

1.0.5 2025-06-23 12:06 UTC

This package is auto-updated.

Last update: 2025-06-23 12:07:34 UTC


README

PocketForm is a powerful and flexible PHP library designed exclusively for creating interactive forms for PocketMine-MP. With an intuitive API and a modular architecture, PocketForm allows developers to easily build various types of forms—ranging from simple button menus to complex custom forms with dynamic validation and interactive elements—tailored for PocketMine environments.

Table of Contents

Features

  • Multiple Form Types:
    Create various form types including simple, custom, and modal forms.
  • Dynamic Form Elements:
    Add interactive elements such as inputs, dropdowns, sliders, step sliders, toggles, and labels.
  • Custom Validation:
    Use built-in validators or define your own using closures.
  • Event Handling:
    Easily attach callback functions for response handling (onResponse), form closing (onClose), and button clicks (onClick).
  • Extensible Architecture:
    Leverage traits and a modular design to extend and customize the library.

Installation

To install PocketForm, use Composer:

add PocketForm to the Required Depencies list in your project like this:

"require": {
    "xanderid/pocketform": "^1.0.3"
  },

Alternatively, clone or download the repository:

git clone https://github.com/XanderID/PocketForm.git

Getting Started

After installation, you can start creating forms immediately. PocketForm provides helper classes and traits that simplify form creation, element management, and response handling.

Usage Examples

Creating a Simple Menu Form

The SimpleForm is ideal for creating menu-based interfaces where the player selects from a list of buttons.

use XanderID\PocketForm\PocketFormHelper;
use XanderID\PocketForm\simple\SimpleFormResponse;

// Create a simple menu form with a title, body, and button options.
$form = PocketFormHelper::menu(
    'Main Menu',
    'Please select an option:',
    ['Play', 'Settings', 'Exit'],
    function (SimpleFormResponse $response) {
        $player = $response->getPlayer();
        // Process button selection using $response->getSelected()
    }
);

// Send the form to the player.
$player->sendForm($form);

Or you can use the Callable Builder:

use XanderID\PocketForm\PocketFormHelper;
use XanderID\PocketForm\Utils;
use pocketmine\player\Player;

$form = PocketFormHelper::menu(
    'Main Menu',
    'Please select an option:',
    ['Play', 'Settings', 'Exit'],
    Utils::createMenuCall([
        fn(Player $player) => $this->serverList($player),
        fn(Player $player) => $this->serverSettings($player)
    ])
);

// Send the form to the player.
$player->sendForm($form);

Docs

For additional documentation, please follow this link.

Whats News

  • Fix Bug
  • Added New Element Divider and Header