email()->validate('user-email');
// check for errors
if ($validator->hasErrors()) {
$_SESSION['errors']['user-form'] = $validator->getAllErrors();
} else {
/* (disabled in demo - no database enabled)
require_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/phpformbuilder/database/db-connect.php';
require_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/phpformbuilder/database/Mysql.php';
$db = new Mysql();
$filter['user_id'] = Mysql::sqlValue($_POST['user_id'], Mysql::SQLVALUE_NUMBER);
$update['civility'] = Mysql::SQLValue($_POST['civility']);
$update['user-name'] = Mysql::SQLValue($_POST['user-name']);
$update['user-first-name'] = Mysql::SQLValue($_POST['user-first-name']);
$update['user-email'] = Mysql::SQLValue($_POST['user-email']);
$skills = json_encode($_POST['skills']);
$update['skills'] = Mysql::SQLValue($skills);
$update['validated'] = Mysql::SQLValue(0); // default value if un-checked
if(isset()) {
$update['validated'] = Mysql::SQLValue(1);
}
if (!$db->UpdateRows('users', $update, $filter)) {
$msg = '
' . $db->error() . '
' . $db->getLastSql() . '
' . "\n";
} else {
*/
$msg = 'Database updated successfully !
'. " \n";
// disabled in demo - no database enabled
// $db->UpdateRows('users', $update, $filter);
// $msg = 'Database updated successfully !
Last query : ' . $db->getLastSql() . '
'. " \n";
/*
}
*/
}
}
if (isset($_GET['user_id']) && is_numeric($_GET['user_id'])) {
$user_id = $_GET['user_id'];
}
if (!isset($_SESSION['errors']['user-form']) || empty($_SESSION['errors']['user-form'])) { // If no error posted
/* Retrieve values from db (disabled in demo - no database enabled)
$db = new Mysql();
$columns = $db->getColumnNames("users");
$qry = "SELECT * FROM users WHERE user_id='$user_id'";
$db->query($qry);
$row = $db->Row();
foreach ($columns as $columnName) {
if($columnName == 'skills') {
$_SESSION['user-form'][$columnName] = json_decode($row->$columnName);
} else {
$_SESSION['user-form'][$columnName] = $row->$columnName;
}
}
*/
// values for demo
$user_id = 1;
$_SESSION['user-form']['civility'] = 'Ms.';
$_SESSION['user-form']['user-name'] = 'Wilson';
$_SESSION['user-form']['user-first-name'] = 'Susan';
$_SESSION['user-form']['user-email'] = 'swilsone@squarespace.com';
$_SESSION['user-form']['validated'] = 1;
$_SESSION['user-form']['skills'] = array('HTML5', 'Bootstrap 4', 'PHP');
}
$form = new Form('user-form', 'horizontal', 'novalidate', 'material');
// $form->setMode('development');
$form->startFieldset('Update User');
$form->addInput('hidden', 'user_id', $user_id);
$form->addRadio('civility', 'M.', 'M.');
$form->addRadio('civility', 'Mrs.', 'Mrs.');
$form->addRadio('civility', 'Ms.', 'Ms.');
$form->printRadioGroup('civility', 'Civility : ');
$form->addInput('text', 'user-name', '', 'Name', 'size=60, required');
$form->addInput('text', 'user-first-name', '', 'First Name', 'size=60, required');
$form->addInput('email', 'user-email', '', 'user-email : ', 'size=60, required');
$form->addCheckbox('validated', '', 1, 'class=lcswitch, data-ontext=Yes, data-offtext=No, data-theme=orange, checked');
$form->printCheckboxGroup('validated', 'Validated');
$form->addOption('skills[]', 'HTML5', 'HTML5');
$form->addOption('skills[]', 'CSS3', 'CSS3');
$form->addOption('skills[]', 'Javascript', 'Javascript');
$form->addOption('skills[]', 'jQuery', 'jQuery');
$form->addOption('skills[]', 'Bootstrap 4', 'Bootstrap 4');
$form->addOption('skills[]', 'PHP', 'PHP');
$form->addOption('skills[]', 'Mysql', 'Mysql');
$form->addSelect('skills[]', 'Skills', 'multiple, required');
$form->addBtn('button', 'cancel', 0, 'cancelCancel', 'class=btn orange darken-1 waves-effect waves-light, data-dismiss=modal', 'btn-group');
$form->addBtn('submit', 'submit-btn', 1, 'Submit check', 'class=btn waves-effect waves-light ladda-button, data-style=zoom-in', 'btn-group');
$form->printBtnGroup('btn-group');
$form->endFieldset();
// jQuery validation
$form->addPlugin('formvalidation', '#user-form');
?>
Material Design Form - Retrieve form values from database
printIncludes('css'); ?>
Php Form Builder - Material Design Form using Database values
Retrieve default field values from database
printIncludes('js');
$form->printJsCode();
?>