PHP code example of one234ru / html-input-generator
1. Go to this page and download the library: Download one234ru/html-input-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 / html-input-generator example snippets
$config = [
'type' => 'text',
'name' => 'something',
];
$value = $_GET['something'] ?? '';
$input = new \One234ru\HTMLinputGenerator($config, $value);
$html = strval($input);
$config = [
'type' => 'text',
'name' => 'something',
'attr' => [
'class' => 'some-class',
'placeholder' => 'Type "something" here'
]
];
$value = 'Text with "quotes" + <script>hackers!</script>';
$config = [
'type' => 'textarea',
'name' => 'something',
'attr' => [
'rows' => 5,
'style' => 'width: 100%; line-height: 1.25;'
]
];
$value = '"quoted" and <script>';
$cfg = [
'type' => 'checkbox',
'name' => 'something',
'value' => 1,
];
$value = '1';
$config = [
'type' => 'submit',
'name' => 'something',
'value' => 'text on the button'
];
$value = 'whatever';
$config = [
'name' => 'secret',
'type' => 'hidden',
];
$value = 'custom';
$config = [
'name' => 'secret',
'type' => 'hidden',
'value' => 'steady'
];
$value = 'custom'; // ignored
$config = [
'type' => 'select',
'name' => 'something',
'options' => [
'' => '(choose)',
1 => 'One',
2 => 'Two',
[
'value' => 3,
'text' => 'Three',
'attr' => [
'data-something' => 'Something',
]
]
]
];
$value = '3';
$config = [
'type' => 'select',
'name' => 'something',
'multiple' => true,
'options' => [
'' => '(choose)',
1 => 'One',
2 => 'Two',
3 => 'Three',
]
];
$value = [ '1', '3' ];
$config = [
'type' => 'select',
'name' => 'something',
'options' => [
'' => '(choose)',
],
'optgroups' => [
[
'attr' => [
'label' => 'First group',
],
'options' => [
1 => 'One',
2 => 'Two',
]
],
[
'attr' => [
'label' => 'Second group',
],
'options' => [
3 => 'Three',
4 => 'Four',
]
]
]
];
$value = '3';
$config = [
'type' => 'tel',
'name' => 'something',
'attr' => [
'placeholder' => 'Enter your phone'
]
];
$value = '+74950000000';