use App\Config\Validation;
...
if (!$this->validate([
'example' => ['label' => '[size=small][font=Monaco, Consolas, Courier, monospace]example[/font][/size]', 'rules' => 'required|min_length[3]']
])) {}
else {}
...
<?php helper('form'); ?>
<form action="../save" class="needs-validation" method="post" accept-charset="utf-8" novalidate>
<?= form_input(array('name' => 'example', 'aria-describedby' => 'bodyHelpBlock', 'class' => 'form-control', 'maxlength' => '100'),'','required');?>
<div class="valid-feedback">Ok!</div>
<div class="invalid-feedback">Oops i did it again!</div>
<?= form_submit(array('name' => 'submit', 'class' => 'btn btn-secondary'),'Save!');?>
</form>
<script>
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function() {
'use strict';
window.addEventListener('load', function() {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>