È possibile creare un polyfill eseguito sul modulo di invio. Ad esempio:
/* 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. */
}
});
});
Questo script attende che il modulo venga inviato, quindi cicli se ogni elemento forma con l'attributo required
ha un valore immesso. Se tutto ha un valore, invia il modulo.
Un elemento di esempio da controllare potrebbe essere:
<input type="file" name="file_input" required="true" />
(È possibile rimuovere i commenti & minify questo codice quando lo si utilizza sul tuo sito web)
fonte
2013-07-15 09:30:08
Avrete bisogno di JavaScript. –
@MadaraUchiha l'opzione javascript è anche buona. Per favore, dillo. – Bere
Si prega di fornire più del file HTML. Suppongo tu abbia un pulsante di invio da qualche parte? Allegare una funzione javascript che asserisce se il campo di input del file è o meno vuoto e, se vuoto, restituire un messaggio di errore. – Tro