PHP code example of mdbottino / forms

1. Go to this page and download the library: Download mdbottino/forms 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/ */

    

mdbottino / forms example snippets


	use mdbottino\Forms\BaseForm;
	use mdbottino\Forms\Fields\TextField;

	class BasicForm extends BaseForm {
	    public function __construct($src=null){
	        $this->fields = [
	            new TextField(
	                'desc',			# Name
	                'Description', 	# Label
	            ),
	        ];
	        parent::__construct($src);
	    }
	}

	# It will render empty (with placeholders if given)
	$addForm = new BasicForm();


	# The folowing will render with the value given to each field.
	
	# Using arrays
	$array = ['desc' => 'some value'];
	$editFormArray = new BasicForm($array);

	# Using objects
	$obj = new \StdClass();
	$obj->desc = 'some other value';
	$editFormObject = new BasicForm($obj);
	

	use mdbottino\Forms\BaseForm;
	use mdbottino\Forms\Fields\TextField;
	use mdbottino\Forms\Fields\EmailField;

	class StyledForm extends BaseForm {
	    public function __construct($src=null){

	        $options = [
	            'attrs' => [
	                'class' => 'form-control', 
	            ],
	        ];

	        $this->fields = [
	            new TextField(
	                'desc',
	                'Description',
	                $options,
	            ),
	            new EmailField(
	                'email',
	                'E-mail address',
	                $options,
	            ),
	        ];

	        parent::__construct($src);
	    }
	}
Blade
    {!! $form->start() !!}
        @csrf
        @foreach ($form->fields() as $field)

            {!! $field->label() !!}
            {!! $field->widget(old($field->name())) !!}

        @endforeach

        <input value="Submit" type="submit" >
        <input value="Reset" type="reset" >

    {!! $form->end() !!}