1. Go to this page and download the library: Download alterfw/php-form-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/ */
alterfw / php-form-generator example snippets
m = Form::create('formaction.php'); // form action attribute
$form
->add(Form::text('user[name]')->setLabel('Username: ')) // adds a text field with a name and wrapped with a div tag
->add(Html::tag('br')) // adds a non-field object
->add(Form::password('user[password]')->setLabel('Password: ')) // adds a password field with a name
->add(Html::tag('br'))
->add(
Form::radios('gender') // create a collection of radio buttons
->add('M', 'Male') // add a radio with value "M" and label "Male"
->add('F', 'Female') // add a radio with value "F" and label "Female"
)
->add('<ul>')
->add(
Form::checkboxes('interests[]') // create a collection of checkboxeseaa
->add('games', 'Games')
->add('animes', 'Animes')
->add('o_thing', 'Other things')
->setWrapper(Html::tag('li')->setClass('li-item')) // changes the wrapper, default is div
)
->add('</ul>')
->add(
Form::select('songs[]')->setMultiple(true) // create a select multiple input
->add('sth', 'Stairway to Heaven')
->add('nem', 'Nothing Else Matters')
->add('fb', 'Free bird')
->add('others', 'Others')
)
->add(
Form::checkbox('newsletter')->setLabel('Receive newsletter? ') // create a single checkbox
);
echo $form; // or echo $form->render()
$form->populate(array(
'user' => array(
'name' => 'myuser_name' // user[name] field
),
'songs' => array('sth', 'fb') // select these two songs for the field songs[]
...
));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.