New Form API plugin for PocketMine-MP +4.0.0

Related tags

Laravel Form
Overview

Form API

New Form API plugin for PocketMine-MP +4.0.0
Report Bug

About this project

There are many Form API plugins available for PocketMine-MP, however, I didn't find one that really suit my needs! so I created this one, Which you can make your UI forms with easy / new methods (I hope so), There is something that you should know before using this API :

  • This FormAPI uses Muqsit's FormImageFix, So if you have this plugin in your server, You need to delete it first!
  • This plugin has a special method of use and it's not like most other published Form API plugins, So please read Usage carefully.

Installation

You need to download PHAR of the plugin in here, After downloading put .PHAR plugin to your plugins folder and start your server, Done!

Usage

Basically before using this API, You should know php, You need to create your own php class, I made this one for myself :


declare(strict_types=1);

namespace TestForm;

class MyClass
{
}

Now follow your ui type example from below table for your next steps :

Quick Access Table
  1. Modal Forms
  2. Simple Forms
  3. Custom Forms

Modal Form

Follow these steps to make a UI modal form:

  1. extend your class to form\ModalForm :
class MyClass extends form\ModalForm
{
}
  1. You need to define title and content functions (If you don't, You'll get Internal server error) :
class MyClass extends form\ModalForm
{
    /* This will be the title of your form */
    protected function title(): string
    {
        return 'The title of your form';
    }

    /* This will be the content of your form */
    protected function content(): string
    {
        return '+ The content of your form';
    }
}
  1. Now you need to define first and second button of your form. (Yes/No buttons)
class MyClass extends form\ModalForm
{
    /* This will be the title of your form */
    protected function title(): string
    {
        return 'Title of your form';
    }

    /* This will be the content of your form */
    protected function content(): string
    {
        return '+ The content of your form';
    }
    
    /* The first button of your form */
    protected function firstButton(): string
    {
        return 'Yes';
    }

    /* The second button of your form */
    protected function secondButton(): string
    {
        return 'No';
    }
}
  1. Now you need to define these two functions for when player click yes / no buttons :
class MyClass extends form\ModalForm
{
    /* This will be the title of your form */
    protected function title(): string
    {
        return 'The title of form';
    }

    /* This will be the content of your form */
    protected function content(): string
    {
        return '+ This is content of your form.';
    }
    
    /* The first button of your form */
    protected function firstButton(): string
    {
        return 'Yes';
    }

    /* The second button of your form */
    protected function secondButton(): string
    {
        return 'No';
    }
    
    /* When player clicks the first button, this function will be executed */
    protected function onClickFirstButton(Player $player): void
    {
        $player->sendMessage('You clicked on Yes button.');
    }

    /* When player clicks the second button OR closes the form, this function will be executed */
    protected function onClickSecondButton(Player $player): void
    {
        $player->sendMessage('You clicked on No button.');
    }
}

Now you're done! Your form is ready for sending to the player with :

$player->sendForm(new MyClass());

Simple Form

  • This will work like ModalForms But instead of 2 buttons, You can define as many buttons as you want, So in this form, there is three new functions, buttons() for registering form buttons and onClickButtons() for when player clicks on form buttons and onClose() for when player closes the form.
class MyClass extends form\SimpleForm
{
    /* This will be the title of your form */
    protected function title(): string
    {
        return 'The title of form';
    }

    /* This will be the content of your form */
    protected function content(): string
    {
        return '+ This is content of your form.';
    }
    
    /* With this function you can register your form buttons */
    protected function buttons(): array
    {
        return [
            'This is first button', # This button does not have image
            'This is second button', # This button does not have image
            'Url image button' => 'https://www.freeiconspng.com/uploads/poop-emoji-png---images-free-download-6.png', # This button have image, The image of this button is set with a URL, Your image Url must start with https or http
            'Path image button' => 'textures/ui/checkboxFilledYellow', # This button have image, The image of this button is set with minecraft path, You can find paths in (https://github.com/KygekDev/default-textures/tree/master/textures)
            'Not exist image' => 'textures/ui/steveJobsFace' # This is a wrong image that is not exist in minecraft path!
        ];
    }

    /* When player clicks on buttons, this function will be executed */
    protected function onClickButton(Player $player, int $button): void
    {
        switch ($button) {
            case 0:
                $player->sendMessage('You clicked on button 1');
                break;
            case 1:
                $player->sendMessage('You clicked on second button');
                break;
            case 2:
                $player->sendMessage('This is button with url image');
                break;
            case 3:
                $player->sendMessage('This button have path image');
                break;
            case 4:
                $player->sendMessage('This image is not exist, You must write the correct path of your image!');
                break;
        }
    }
    
    /* When player closes the form, this function will be executed */
    protected function onClose(Player $player): void
    {
        $player->sendMessage('You closed the form');
    }
}

Now you're done! Your form is ready for sending to the player with :

$player->sendForm(new MyClass());

Custom Form

  • This is like SimpleForms but with a little bit diffrent, In content() of these forms you need to add form entries (Like addLabel(), addDropdown(), addInput(), addSlider() and addStepSlider()) and Also Instead of onClickButton() you need onSubmit() function, Look at the code :
class MyClass extends form\SimpleForm
{
    /* This will be the title of your form */
    protected function title(): string
    {
        return 'The title of form';
    }

    /* Just add content in this method (Content like: Dropdown, Label, Input, Slider, StepSlider) */
    protected function content(): void
    {
        $this->addLabel('+ Did you just learbed ?');
        $this->addInput('Your answer :', 'Write your answer here...', 'Yes, Tysm :).');
        // You can also define Dropdown, StepSlider, Slider here!
    }

    /* When player clicks the submit button, this function will be executed */
    protected function onSubmit(Player $player, array $data): void
    {
        /* $data[0] is the first thing we added to our content (Here is label) So the second thing we added is input, We can get result of our input with below variable : */
        $input = $data[1];
        $player->sendMessage('Your answer is : ' . $input);
    }
    
    /* When player closes the form, this function will be executed */
    protected function onClose(Player $player): void
    {
        $player->sendMessage('You closed the form');
    }
}

Now you're done! Your form is ready for sending to the player with :

$player->sendForm(new MyClass());
You might also like...
🧙‍♀️ Arcanist takes the pain out of building multi-step form wizards in Laravel.
🧙‍♀️ Arcanist takes the pain out of building multi-step form wizards in Laravel.

Installation Arcanist requires PHP 8 and Laravel 8. composer require laravel-arcanist/arcanist Documentation You can find the full documentation here

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Reactive Form Builder for Vue.js with Laravel Support
Reactive Form Builder for Vue.js with Laravel Support

Dynamic Form Builder for Laravel with Vue.js Create even the most complex forms with ease, using two-sided validation, eloquent, nested elements, cond

A TALL-based Laravel Livewire component to replace the (multiple) select HTML input form with beautiful cards.
A TALL-based Laravel Livewire component to replace the (multiple) select HTML input form with beautiful cards.

TALL multiselect cards A TALL-based Laravel Livewire component to replace the (multiple) select HTML input form with beautiful cards. Table of content

Generate form validators for Laravel: an extension of way/generators

Laravel Form Validator Contents Introduction Installation Usage Example Tests Introduction After using Jeffrey Way's Generator and his Validator packa

Rapid form generation with Bootstrap 3 and Laravel.

Important: This package is not actively maintained. For bug fixes and new features, please fork. BootForms BootForms builds on top of my more general

This package can use form request just as Laravel do.

Lumen Form Request This package can use form request just as Laravel do. Installation Install by composer $ composer require chhw/form-request In

A package to validate email domains in a user registration form
A package to validate email domains in a user registration form

Laravel Email Domain Rule This package allows to define a subset of allowed email domains and validate any user registration form with a custom rule.

A quick and incomplete example of how to validate a form using a FormValidator class on the simple-mvc
A quick and incomplete example of how to validate a form using a FormValidator class on the simple-mvc

Simple MVC Description This repository is a simple PHP MVC structure from scratch. It uses some cool vendors/libraries such as Twig and Grumphp. For t

Owner
RedSkyFallPM
My minecraft bedrock edition open source plugins.
RedSkyFallPM
Composer package which adds support for HTML5 elements using Laravels Form interface (e.g. Form::date())

Laravel HTML 5 Inputs Composer package which adds support for HTML5 elements by extending Laravel's Form interface (e.g. Form::date()) Adds support fo

Small Dog Studios 11 Oct 13, 2020
This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.

Laravel Verify New Email Laravel supports verifying email addresses out of the box. This package adds support for verifying new email addresses. When

Protone Media 300 Dec 30, 2022
Register for multiple Livestorm sessions from an external form. Practical use of Livestorm API with PHP/Javascript.

Livestorm Multi Session Registration Register for multiple Livestorm sessions from an external form. Practical use of Livestorm API with PHP/Javascrip

Nathan CHEVALIER 0 Dec 24, 2021
This is a plugin written in the PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform. It helps to liven up your server with Tags!

General This is a plugin written in the PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform.

Thành Nhân 4 Oct 21, 2021
Plugin for Filament Admin that adds a dropdown menu to the header to quickly create new items.

Filament Quick Create Plugin for Filament Admin that adds a dropdown menu to the header to quickly create new items from any page. Installation Instal

Adam Weston 45 Dec 27, 2022
Laravel Form builder for version 5+!

Laravel 5 form builder Form builder for Laravel 5 inspired by Symfony's form builder. With help of Laravels FormBuilder class creates forms that can b

Kristijan Husak 1.7k Dec 31, 2022
Razorpay payment gateway integration in laravel with submit form and storing details in payment table.

Integrating razorpay payment gateway in laravel with submit form and storing payment details in payment table. How to settup the project in your local

Mohammed-Thamnees 3 Apr 15, 2021
A sample application with a multistep form built with Livewire.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

David Grzyb 11 Nov 26, 2022
Laravel Livewire form component with declarative Bootstrap 5 fields and buttons.

Laravel Livewire Forms Laravel Livewire form component with declarative Bootstrap 5 fields and buttons. Requirements Bootstrap 5 Installation composer

null 49 Oct 29, 2022
A package to validate email domains in a user registration form

This package allows to define a subset of allowed email domains and validate any user registration form with a custom rule.

H-FARM 56 Jul 19, 2022