PHP code example of jayrchamp / simple-php-form-builder

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

    

jayrchamp / simple-php-form-builder example snippets


$form = new SimplePhpFormBuilder\Form();

$form->action('/page/submit.php')->open();

$form->id('form_id')
     ->action('/page/submit.php')
     ->method('POST')
     ->class('form_class1')->class(['form_class2', 'form_class3'])
     ->attr(['data-form' => 'form-data'])
     ->enctype('multipart/form-data')
     ->open();


$form->field( string $type )->label( string $label )->build();

$form->field( 'text' )
     ->label('What is your name?')
     ->name('name')
     ->placeholder('ie.: John Doe')
     ->id('text_id')
     ->class('text_class1')->class(['text_class2', 'text_class3'])
     ->attr(['data-text' => 'text-data'])
     ->attr('

$form->field('submit')->value('Send')->build();

$form->close();

$form->field('select')
     ->label('Where do you want to go?')
     ->placeholder('Select')
     ->addOption('To the beach')
     ->addOption('Las vegas')
     ->addOption('Planet Mars')
     ->build();

$form->field('checkbox')->label('Banana')->name('Favorite Fruits[]')->build();
$form->field('checkbox')->label('Apple')->name('Favorite Fruits[]')->build();
$form->field('checkbox')->label('Kiwi')->name('Favorite Fruits[]')->build();

$form->field('radio')->label('Canada')->name('Favorite_country')->build();
$form->field('radio')->label('USA')->name('Favorite_country')->build();
$form->field('radio')->label('China')->name('Favorite_country')->build();

$form->field('hidden')->name('my hidden field')->value('done')->build();
bash
composer