PHP code example of one234ru / form-inputs-generator

1. Go to this page and download the library: Download one234ru/form-inputs-generator 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/ */

    

one234ru / form-inputs-generator example snippets


$config = [
    'type' => 'text',
    'name' => 'something',
];
$obj_1 = new One234ru\HTMLinputGenerator($config, $_GET['something'] ?? '');
$obj_2 = new One234ru\FormInputsGenerator($config, $_GET); 
var_dump( strval($obj_1) === strval($obj_2) ); // true

$config = [
	'type' => 'checkbox',
	'name' => 'something',
	'value' => 1,
	'label' => 'Something'
];

[
	...
	'label' => [
		'attr' => [
			'class' => 'label-for-something',
		],
		'text_wrapper' => [
			'tag' => 'div',
			'attr' => [
				'class' => 'text-for-something'
			],
		],
		'text' => '<b>Something</b>',
	]
]

	'label' => 'Something'

	'label' => [
		'text' => 'Something'
	]

$config = [
	'type' => 'radio',
	'name' => 'something',
	'values' => [
		1 => 'One', 
		[
			'value' => 2,
			'label' => 'Two', 
		],
		[
			'value' => 3,
			'label' => [
				'attr' => [
					'class' => 'special-label',
				],
				'text' => 'Three', 
			],
		],
		[
			'value' => 4,
		]
	]
];

[
	'value' => 1,
	'label' => 'One'
]

$config = [
	'type' => 'radio',
	'name' => 'something',
	'attr' => [
		'class' => 'standard-input',
	],
	'label' => [
		'attr' => [
			'class' => 'standard-label',
		],
	], 
	'values' => [
		1 => 'One', 
		[
			'value' => 2,
			'label' => 'Two', 
		],
		[
			'value' => 3,
			'label' => [
				'attr' => [
					'class' => 'special-label', // Will override top-level value
				],
				'text' => 'Three', 
			],
		],
		[
			'attr' => [
				'class' => 'special-input', // Will override top-level value
			],
			'value' => 4,
		]
	]
];

$config = [
	'type' => 'checkbox',
	'name' => 'something',
	'values' => ...
];

[
	'type' => 'checkbox',
	'name' => 'something',
	'value' => 1,
	'off_value' => 0
]

[
	'type' => 'checkbox',
	'name' => 'something',
	'value' => 1,
	'off_value' => 0,
	'label' => 'Something', 
	'attr' => [
		'class' => 'some-class',
	]
]