Search
 
SCRIPT & CODE EXAMPLE
 

PHP

form submitting twice

// Use the ID of "submit-form" in the form tag and class of "submit-button" in the submit tag
// Like this <form id="submit-form" action="" method="POST">
// And this <button type="submit" id="submit" class="submit-button">Submit</button>
// And use the script below to check if it is not empty, and most importantly, the required ones are not empty. I don't think there's a point trying to force unrequired inputs to be set if you did not include that in your HTML
<script>
    (function(){
    $('.submit-button').on('submit', function(){
      var thisFormInput = document.querySelector('#submit-form');
      var thisFormInputCount = thisFormInput.length;
      var errors = 0;

      for (var i = 0; i < thisFormInputCount; i++) {
        if (thisFormInput[i].value === '' && thisFormInput[i].required === true) {
          errors++;
        }
      }

      if (count === 0) {
        // Disable the button so that it cannot be further clicked
        document.querySelector("#submit").disabled = true;
        
        // If you want, include font awesome in your header then this can replace the button text with a spinner
        document.querySelector("#submit").innerHTML = '<i class="fa fa-circle-o-notch fa-spin" style="font-size:16px"></i>';
      }
    })
    })();
</script>
Comment

PREVIOUS NEXT
Code Example
Php :: php iterate through array 
Php :: php remove specific element from array 
Php :: How to add new column in table laravel 
Php :: add column migration laravel 
Php :: proper permission webserver laravel 
Php :: get original name without mutant model laravel 
Php :: php is scan dir recursive? 
Php :: appending txt file from php 
Php :: php how to write at end of the sentence 
Php :: Searching the array for multiple values 
Php :: php nan 
Php :: php convert hex to rgba 
Php :: remove decimal php 
Php :: laravel print query with parameters 
Php :: downgrade php version vagrant 
Php :: concat() function using laravel eloquent query 
Php :: blade foreach key value 
Php :: laravel get last get request 
Php :: php force download csv 
Php :: check if date is past php 
Php :: format datetime ISO php 
Php :: php number positive 
Php :: include a file in laravel controller 
Php :: Cross-site request forgery validation failed. Required param "state" missing from persistent data 
Php :: how to truncate the given string to the specified length in blade.php 
Php :: how to get random element from a given array via php faker in laravel 
Php :: bin to dec php 
Php :: larevel version artisan 
Php :: laravel change column 
Php :: add request data in laravel request 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =