1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Get result of 'toggle' using formAPI

Discussion in 'Development' started by Levi, Jun 8, 2018.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    i saw a person comment this:
    PHP:
     $form $this->getServer()->getPluginManager()->getPlugin("FormAPI")->createCustomForm(function (Player $sender, array $data) {
        
    var_dump($data); // Sends all data to console
    });
    $form->setTitle("Form Title");
    $form->addLabel("Text");
    $form->addToggle("Toggle");
    $form->addSlider("Slider"1100); // Slider, Min 1, Max 100
    $form->addStepSlider("Step Slider", ["5""10""15"]); // Step Slider, 5, 10 & 15
    $form->addDropdown("Dropdown", ["1""2""3"]); // Dropdowm, Options 1, 2 & 3
    $form->addInput("Input""Ghost Text""Text"); // Input, Text already entered 
    but how do you get the result for toggle, sliders, dropdown, inputs?
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Shouldn't that be in $data?
     
  3. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    For toggle i tried case 0: if $data == true $sender->sendMessage(true)
    It didn't work
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    The code you sent is var_dumping the value of $data to console, take a lookat that to see what the data looks like
     
    Levi likes this.
  5. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    i did, but I don't get the result if its true

    PHP:
     $form $this->core->getServer()->getPluginManager()->getPlugin("FormAPI")->createCustomForm(function (Player $player, array $data) {
                
    var_dump($data);
                
    $result $data[0];
                switch (
    $result) {
                    case 
    :
                        if (
    $result == true) {
                            
    $player->sendMessage("true");
                        } else {
                            
    $player->sendMessage("false");
                        }
                        return;

                }
            });
            
    $form->setTitle("Form Title");
            
    $form->addToggle("Toggle");
    I get the false message when i switch it to false and submit but i dont get any message when i toggle the switch to true

    var dump
    Code:
    array(1) {
      [0]=>
      bool(true)
    }
    array(1) {
      [0]=>
      bool(false)
    }
    
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Learn PHP: https://php.net/switch https://php.net/if

    Why do you switch($result)?
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.