1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
| <div id="form">
{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
<div class ="identif">
{{ form_label(form.identif, 'ID ', {'label_attr': {'for': 'identif'}}) }}
<span class="error" title="This field is required" > *</span>
{{ form_widget(form.identif, {'attr': {'id': 'identif', 'name' : "identif", 'placeholder' : 'alouette.mignonne'}}) }}
<span class="error-message">error</span>
{{ form_errors(form.identif) }}
</div>
<div class ="mail">
{{ form_label(form.mail, 'Votre Email', {'label_attr': {'for': 'mail'}}) }}
<span class="error" title="This field is required" > *</span>
{{ form_widget(form.mail, {'attr': {'id': 'mail', 'name' : 'mail', 'placeholder' : 'Ex: mignonne@hotmail.fr'}}) }}
<span class="error-message">error</span>
{{ form_errors(form.mail) }}
</div>
<div class ="sender">
<input type="submit" id="envoi" value="Continuer ..."/>
</div>
{{ form_end(form) }}
</div>
{% block javascripts %}
<script>
app = {
/*
* Fonction appelée au chargement du DOM
*/
init: function() {
console.info("app.init");
// J'écoute le clic sur le bouton d'envoi...
$("#envoi").on("click", this.monSubmit)
},
/*
* Handler du submit
*/
monSubmit: function(e){
console.info("app.monSubmit")
// On arrête le chargment de la page
e.preventDefault()
// Appel de la fonction pour la vérif...
app.stopChamp()
},
stopChamp: function(){
console.info("app.stopChamp")
if($("input[type=submit]")){ // Start test
var error = []
// PREMIER TEST CETTE DONNEE DOIT ETRE DE TYPE STRING SINON ERREUR essaye sinon un document.getElementById('identif').value à la place si jamais ...
console.log(typeof $('#identif').val())
if($("#identif").val() == "" ){
// On sélectionne le span qui à la class : error-message avec ".next"
error["identif"] = $("#identif").next(".error-message").fadeIn(1000).text("Veuillez bien renseigner le champ")
}else{
if(!$("#identif").val().match(/^[a-z]+$/i)){
error["identif"] = $("#identif").next(".error-message").fadeIn(1000).text("Nom dans l'url pas valide")
}else
$("#identif").next(".error-message").fadeOut()
}
//DEUXIEME TEST ICI PAREIL
console.log(typeof $('#mail').val())
if($("#mail").val() == ""){
error["mail"] = $("#mail").next(".error-message").fadeIn(1000).text("Veuillez bien renseigner l'email")
}else{
if(!$("#mail").val().match(/^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$/)){
error["mail"] = $("#mail").next(".error-message").fadeIn(1000).text("Votre email n'est pas valide")
}
else
$("#mail").next(".error-message").fadeOut()
}
if(!error["mail"] && !error["identif"]){
var $this = $("input[type=submit]")
$this.attr("disabled", "disabled")
setTimeout(function(){
$this.attr("value", "Chargement...")
.css({
opacity : 0.4,
cursor : "not-allowed"
})
},300)
// Appel de la fonction qui fera la requête Ajax
app.reqAjax()
return false
}
}// End test
},
reqAjax: function(){
console.info("app.reqAjax")
// On récupère l'url et le type
//var url = this.action
var url = "{{path('home')}}"
// On récupère les infos (identif et mail)
var data = $(".form").serialize()
// On fait la requête
$.ajax({
url: url,
type: "POST",
dataType: "html",
data: data,
beforeSend:function(){
$('#envoi').val('Patientez...').fadeIn("slow")
},
success: app.showSuccess()
})
},
showSuccess: function(body,statut){
console.info("app.showSuccess")
// On crée la div qui servira de griser le fond....
var popup = $("<div>",{
class: "test",
css:{
background: "rgba(0,0,0,.8)",
width: "100%",
height: "100%",
position: "fixed",
top: 0,
left: 0,
"z-index": 1
}
})
// On ajoute la DIV (grisée) au body
$("body").append(popup)
// On l'a fait apparaitre après quelques sécondes...
popup.fadeTo(600, 0.5, function () {
// On fait apparaitre le POPUP ,après quelques sécondes...
$(".recupPopup").fadeIn(4000)
// Je lance le chargement
app.load()
setTimeout(function(){
window.location.href = "starpass-security.php";
}, 6000)
})
},
/*
* Lance le chargement
*/
load: function() {
console.info("app.load")
// J'anime #progress
$("#progress").animate({
width: "100%",
opacity: 0.5
},{
duration: 5999,
easing: "linear",
step: function(now, tween) { // Callback � chaque �tape
// Je calcule seulement sur width
if(tween.prop == "width") {
// On arrondit
now = parseInt(now)
// On rajoute le "%"
now = now + " %"
// On affiche
/*
* $(this) = $("#progress"),
* car c'est #progress qui lance cette fonction
*/
/* ("#progress").text(now) */
$(this).text(now)
}
}
})
}
}
$(document).ready(function(){
app.init();
});
</script>
{% endblock %} |
Partager