Możesz utworzyć polyfill, który zostanie wykonany na formularzu submit. Na przykład:
/* Attach the form event when jQuery loads. */
$(document).ready(function(e){
/* Handle any form's submit event. */
$("form").submit(function(e){
e.preventDefault(); /* Stop the form from submitting immediately. */
var continueInvoke = true; /* Variable used to avoid $(this) scope confusion with .each() function. */
/* Loop through each form element that has the required="" attribute. */
$("form input[required]").each(function(){
/* If the element has no value. */
if($(this).val() == ""){
continueInvoke = false; /* Set the variable to false, to indicate that the form should not be submited. */
}
});
/* Read the variable. Detect any items with no value. */
if(continueInvoke == true){
$(this).submit(); /* Submit the form. */
}
});
});
Ten skrypt czeka formularz należy złożyć, a następnie pętli choć każdy element formularza, który ma atrybut required
ma wprowadzoną wartość. Jeśli wszystko ma wartość, przesyła formularz.
Przykładem elementów podlegających kontroli mogą być:
<input type="file" name="file_input" required="true" />
(można usunąć komentarzach & Minify tego kodu przy użyciu go na swojej stronie internetowej)
Musisz JavaScript. –
@ javascriptUvasha opcja javascript jest również dobra. Proszę powiedzieć. – Bere
Podaj więcej pliku HTML. Zakładam, że masz gdzieś przycisk do przesłania? Dołącz funkcję javascript, która zapewnia, czy pole wejściowe pliku jest puste, czy nie, a jeśli puste, zwróć komunikat o błędzie. – Tro