PHP code example of sinevia / php-library-form
1. Go to this page and download the library: Download sinevia/php-library-form 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/ */
sinevia / php-library-form example snippets
$form = \Sinevia\Form::build($fields)->toHtml();
$isValidOrErrors = \Sinevia\Form::validate($fields);
[
'type' => 'text',
'name' => 'FirstName',
'label' => 'First name',
'width' => 6,
'rule' => '
function formProfileFields($user) {
$countriesList = \App\Models\Countries\Country::all()->pluck('Name', 'Iso2')->toArray();
asort($countriesList);
$countries = ['' => '- country -'] + $countriesList;
$daysRange = range(1, 12);
$days = [
'' => '- day -'
];
foreach ($daysRange as $day) {
$days[$day] = $day;
}
$monthsRange = range(1, 12);
$months = [
'' => '- month -'
];
foreach ($monthsRange as $month) {
$months[$month] = $month;
}
$yearsRange = range(1940, 2014);
$years = [
'' => '- year -'
];
foreach ($yearsRange as $year) {
$years[$year] = $year;
}
$fields = [
[
'type' => 'html',
'html' => '<style>.btn-success { width:100%; padding:10px;}</style>',
],
[
'type' => 'html',
'html' => '<div class="col-sm-12"><h3>Profile</h3></div>',
],
[
'type' => 'text',
'name' => 'FirstName',
'label' => 'First name',
'width' => 6,
'rule' => 'ired',
'value' => is_null($user->Birthday) ? '' : date('Y', strtotime($user->Birthday)),
],
[
'type' => 'html',
'html' => '<div class="col-sm-12"><h3>Address</h3></div>',
],
[
'type' => 'select',
'name' => 'Country',
'label' => 'Country',
'options' => $countries,
'width' => 6,
'rule' => '\Form::validate($this->formProfileFields($user));
if(is_array($isValidOrErrorArray)){
// Validation failed, show errors
} else {
// Validation was successful
}