Detailed explanations here: Material Design Forms
<?php
use phpformbuilder\Form;
use phpformbuilder\Validator\Validator;
/* =============================================
Start session and include the autoloader
============================================= */
session_start();
include_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/php/phpformbuilder/phpformbuilder/autoload.php';
/* ==================================================
The Form
================================================== */
$form = new Form('input-with-addons', 'horizontal', 'novalidate', 'material');
$form->setMode('development');
/* Input with icon
-------------------------------------------------- */
$form->startFieldset('Input with icon', 'class=border-bottom pb-4', 'class=grey-text lighten-1 pb-4');
$form->setCols(3, 9);
$form->addIcon('input-with-icon-after', '<i class="material-icons">person</i>', 'after');
$form->addInput('text', 'input-with-icon-after', '', 'Your name', 'required');
$form->addIcon('input-with-icon-before', '<i class="material-icons">person</i>', 'before');
$form->addInput('text', 'input-with-icon-before', '', 'Your name', 'required');
$form->setCols(0, 12);
$form->addIcon('input-with-icon-and-helper', '<i class="material-icons">person</i>', 'after');
$form->addHelper('Your name', 'input-with-icon-and-helper');
$form->addInput('text', 'input-with-icon-and-helper', '', '', 'required');
$form->addIcon('input-with-icon-and-placeholder', '<i class="material-icons">person</i>', 'after');
$form->addInput('text', 'input-with-icon-and-placeholder', '', 'Your name', 'required');
$form->endFieldset();
/* Input with Button
-------------------------------------------------- */
$form->startFieldset('Input with button', 'class=border-bottom pb-4', 'class=grey-text lighten-1 pb-4');
$form->setCols(3, 9);
$addon = '<button class="btn grey darken-1 waves-effect waves-light" type="button" onclick="document.getElementById(\'input-with-button-after\').value=\'\';">reset</button>';
$form->addAddon('input-with-button-after', $addon, 'after');
$form->addInput('text', 'input-with-button-after', '', 'Your name', 'required');
$addon = '<button class="btn grey darken-1 waves-effect waves-light" type="button" onclick="document.getElementById(\'input-with-button-before\').value=\'\';">reset</button>';
$form->addAddon('input-with-button-before', $addon, 'before');
$form->addInput('text', 'input-with-button-before', '', 'Your name', 'required');
$form->setCols(0, 12);
$addon = '<button class="btn grey darken-1 waves-effect waves-light" type="button" onclick="document.getElementById(\'input-with-button-and-helper\').value=\'\';">reset</button>';
$form->addAddon('input-with-button-and-helper', $addon, 'after');
$form->addHelper('Your name', 'input-with-button-and-helper');
$form->addInput('text', 'input-with-button-and-helper', '', '', 'required');
$addon = '<button class="btn grey darken-1 waves-effect waves-light" type="button" onclick="document.getElementById(\'input-with-button-and-placeholder\').value=\'\';">reset</button>';
$form->addAddon('input-with-button-and-placeholder', $addon, 'after');
$form->addInput('text', 'input-with-button-and-placeholder', '', 'Your name', 'required');
$form->endFieldset();
/* Input with Text
-------------------------------------------------- */
$form->startFieldset('Input with text', 'class=border-bottom pb-4', 'class=grey-text lighten-1 pb-4');
$form->setCols(3, 9);
$addon = '$';
$form->addAddon('input-with-text-after', $addon, 'after');
$form->addInput('number', 'input-with-text-after', '', 'Number', 'required');
$addon = '$';
$form->addAddon('input-with-text-before', $addon, 'before');
$form->addInput('number', 'input-with-text-before', '', 'Number', 'required');
$form->setCols(0, 12);
$addon = '$';
$form->addAddon('input-with-text-and-helper', $addon, 'after');
$form->addHelper('Number', 'input-with-text-and-helper');
$form->addInput('number', 'input-with-text-and-helper', '', '', 'required');
$addon = '$';
$form->addAddon('input-with-text-and-placeholder', $addon, 'after');
$form->addInput('number', 'input-with-text-and-placeholder', '', 'Number', 'required');
$form->endFieldset();
/* Input with Button & icon
-------------------------------------------------- */
$form->startFieldset('Input with button & icon', 'class=border-bottom pb-4', 'class=grey-text lighten-1 pb-4');
$form->setCols(3, 9);
$form->addIcon('input-with-button-and-icon-after', '<i class="material-icons">person</i>', 'before');
$addon = '<button class="btn orange darken-1 waves-effect waves-light" type="button" onclick="document.getElementById(\'input-with-button-and-icon-after\').value=\'\';">reset</button>';
$form->addAddon('input-with-button-and-icon-after', $addon, 'after');
$form->addInput('text', 'input-with-button-and-icon-after', '', 'Your name', 'required');
$addon = '<button class="btn orange darken-1 waves-effect waves-light" type="button" onclick="document.getElementById(\'input-with-button-and-icon-before\').value=\'\';">reset</button>';
$form->addAddon('input-with-button-and-icon-before', $addon, 'before');
$form->addIcon('input-with-button-and-icon-before', '<i class="material-icons">person</i>', 'after');
$form->addInput('text', 'input-with-button-and-icon-before', '', 'Your name', 'required');
$form->setCols(0, 12);
$form->addIcon('input-with-button-and-icon-and-helper', '<i class="material-icons">person</i>', 'before');
$addon = '<button class="btn orange darken-1 waves-effect waves-light" type="button" onclick="document.getElementById(\'input-with-button-and-icon-and-helper\').value=\'\';">reset</button>';
$form->addAddon('input-with-button-and-icon-and-helper', $addon, 'after');
$form->addHelper('Your name', 'input-with-button-and-icon-and-helper');
$form->addInput('text', 'input-with-button-and-icon-and-helper', '', '', 'required');
$form->addIcon('input-with-button-and-icon-and-placeholder', '<i class="material-icons">person</i>', 'before');
$addon = '<button class="btn orange darken-1 waves-effect waves-light" type="button" onclick="document.getElementById(\'input-with-button-and-icon-and-placeholder\').value=\'\';">reset</button>';
$form->addAddon('input-with-button-and-icon-and-placeholder', $addon, 'after');
$form->addInput('text', 'input-with-button-and-icon-and-placeholder', '', 'Your name', 'required');
$form->endFieldset();
/* Input with date picker & reset button
-------------------------------------------------- */
$form->startFieldset('Input with date picker & reset button', 'class=border-bottom pb-4', 'class=grey-text lighten-1 pb-4');
$form->setCols(3, 9);
$addon = '<button class="btn orange darken-1 waves-effect waves-light" type="button" onclick="document.getElementById(\'date-pickup\').value=\'\';">reset</button>';
$form->addAddon('date-pickup', $addon, 'after');
$form->addInput('text', 'date-pickup', '', 'Pick a date please', 'data-litepick=true, required');
$form->endFieldset();
/* Select with Button
-------------------------------------------------- */
$form->startFieldset('Select with button', 'class=border-bottom pb-4', 'class=grey-text lighten-1 pb-4');
$addon = '<button class="btn orange darken-1 waves-effect waves-light" type="button" onclick="window.slimSelects[\'select-with-button-after\'].set(null);">reset</button>';
$form->addAddon('select-with-button-after', $addon, 'after');
$form->addOption('select-with-button-after', '', 'Choose one ...', '', 'disabled selected');
$form->addOption('select-with-button-after', 'Mr', 'Mr');
$form->addOption('select-with-button-after', 'Mrs', 'Mrs');
$form->addSelect('select-with-button-after', 'Prefix', 'data-slimselect=true, required');
$addon = '<button class="btn orange darken-1 waves-effect waves-light" type="button" onclick="window.slimSelects[\'select-with-button-before\'].set(null);">reset</button>';
$form->addAddon('select-with-button-before', $addon, 'before');
$form->addOption('select-with-button-before', '', 'Choose one ...', '', 'disabled selected');
$form->addOption('select-with-button-before', 'Mr', 'Mr');
$form->addOption('select-with-button-before', 'Mrs', 'Mrs');
$form->addSelect('select-with-button-before', 'Prefix', 'data-slimselect=true, required');
$form->endFieldset();
/* Select with Button + icon
-------------------------------------------------- */
$form->startFieldset('Select with button & icon', 'class= pb-5', 'class=grey-text lighten-1 pb-4');
$form->addIcon('select-with-button-and-icon-after', '<i class="material-icons">person</i>', 'before');
$addon = '<button class="btn orange darken-1 waves-effect waves-light" type="button" onclick="window.slimSelects[\'select-with-button-and-icon-after\'].set(null);">reset</button>';
$form->addAddon('select-with-button-and-icon-after', $addon, 'after');
$form->addOption('select-with-button-and-icon-after', '', 'Choose one ...', '', 'disabled selected');
$form->addOption('select-with-button-and-icon-after', 'Mr', 'Mr');
$form->addOption('select-with-button-and-icon-after', 'Mrs', 'Mrs');
$form->addSelect('select-with-button-and-icon-after', 'Prefix', 'data-slimselect=true, required');
$addon = '<button class="btn orange darken-1 waves-effect waves-light" type="button" onclick="window.slimSelects[\'select-with-button-and-icon-before\'].set(null);">reset</button>';
$form->addAddon('select-with-button-and-icon-before', $addon, 'before');
$form->addIcon('select-with-button-and-icon-before', '<i class="material-icons">person</i>', 'after');
$form->addOption('select-with-button-and-icon-before', '', 'Choose one ...', '', 'disabled selected');
$form->addOption('select-with-button-and-icon-before', 'Mr', 'Mr');
$form->addOption('select-with-button-and-icon-before', 'Mrs', 'Mrs');
$form->addSelect('select-with-button-and-icon-before', 'Prefix', 'data-slimselect=true, required');
$form->centerContent();
$form->addBtn('submit', 'submit-btn', 1, 'Submit', 'class=btn waves-effect waves-light');
$form->endFieldset();
// Javascript validation
$form->addPlugin('formvalidation', '#input-with-addons');
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Material Form - Input with Addons examples</title>
<meta name="description" content="Material Form - how to create Input with Addons with Php Form Builder">
<link rel="canonical" href="https://www.phpformbuilder.pro/templates/material-forms/input-with-addons.php" />
<!-- Materialize CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!-- Material icons CSS -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<?php $form->printIncludes('css'); ?>
</head>
<body>
<h1 class="text-center">Material Form - <small>Input and select with icon, button and text Addons</small></h1>
<div class="container">
<?php
// information for users - remove this in your forms
include_once '../assets/material-forms-notice.php';
?>
<div class="row">
<div class="col m11 l10">
<div class="center-align">
<a href="https://www.phpformbuilder.pro/documentation/class-doc.php#add-addon" class="btn grey darken-1 waves-effect waves-light btn-small"><strong>Icons & addons</strong> - documentation here <i class="material-icons right">arrow_right</i></a>
<p> </p>
</div>
<?php
$form->render();
?>
</div>
</div>
</div>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<!-- Materialize JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
M.AutoInit(document.querySelector('#input-with-addons'));
});
</script>
<?php
$form->printIncludes('js');
$form->printJsCode();
?>
</body>
</html>