Welcome Guest, Not a member yet? Register   Sign In
Form Data reset before submit
#4

(This post was last modified: 09-05-2018, 05:02 AM by Nome.)

I agree, this is more true for CI3...

In CI4 just specify the:
PHP Code:
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> 

Also I will add that in bootstrap there are methods of check of fields on the party of the user (Validation), perhaps it will be convenient for you.
Reply


Messages In This Thread
Form Data reset before submit - by sanjaya - 09-05-2018, 04:19 AM
RE: Form Data reset before submit - by sanjaya - 09-05-2018, 04:24 AM
RE: Form Data reset before submit - by qury - 09-05-2018, 04:39 AM
RE: Form Data reset before submit - by Nome - 09-05-2018, 05:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB