PHP code example of gustiawan / laravel-form-builder

1. Go to this page and download the library: Download gustiawan/laravel-form-builder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gustiawan / laravel-form-builder example snippets


    /**
     * Set your default styling 
     * the option is [tailwind, bootstrap]
     */
    "style" => "tailwind",

    /**
     * Fill this with your view path
     */
    "form_template" => null
 artisan make:form {name}

use Gustiawan\FormBuilder\Form;

class ExampleForm extends Form
{
    public function handle() 
    {
        $this->text("textinput", "Text Input");
        $this->password("password", "Old Password");
        $this->textArea("text area", "Text Area", "Default Value");
        $this->date("example_date", "Example Date");
        $this->radio("radio_example", "Radio Example", [1 => "Option one", 2 => "Option two"], ["value" => 1]); // default value
        $this->checkBox("checkbox_example", "Checkbox Example", [1 => "Option one", 2 => "Option two"], ["value" => [1, 2]]); // default value must be array
        $this->select("select_field", "Select Field Example", [1 => "Option one", 2 => "Option two"], ["value" => 1]); // default value
    }
}

public function example() 
{
    $form = new ExampleForm([
        "action" => route('example_routes'),
        "method" => "POST",
        // optional
        "data" => [
            "field_name" => "some value"
        ]
    ]);

    return view('example_view', compact('form'));
}

<x-form-generator-form :form="$form" />

$this->text("textinput", "Text Input", ["value" => "some value"]);

$this->text("textinput", "Text Input", ["

$this->text("textinput", "Text Input", ["readonly" => true]);

$this->text("textinput", "Text Input", ["disabled" => true]);

$this->text("textinput", "Text Input", ["class" => "datetimepicker"]);