11550 sujets

JavaScript, DOM et API Web HTML5

Bonjour,

J'ai beau entrer des noms et des adresses e mail corrects, ils sont toujours considérés comme erronés et le message d'erreur s'affiche.
Quel en est la cause?
Merci de m'aider.

$(function() {

	// load the modal window
	$('a.modal').click(function(){

		// scroll to top
		$('html, body').animate({scrollTop:0}, 'fast');

		// before showing the modal window, reset the form incase of previous use.
		$('.success, .error').hide();
		$('form#contactForm').show();
		
		// Reset all the default values in the form fields
		$('#name').val('Votre nom');
		$('#email').val('Votre adresse e-mail');
		$('#comment').val('Votre message');

		//show the mask and contact divs
		$('#mask').show().fadeTo('', 0.7);
		$('div#contact').fadeIn();

		// stop the modal link from doing its default action
		return false;
	});

	// close the modal window is close div or mask div are clicked.
	$('div#close, div#mask').click(function() {
		$('div#contact, div#mask').stop().fadeOut('slow');

	});

	$('#contactForm input').focus(function() {
		$(this).val(' ');
	});
	
	$('#contactForm textarea').focus(function() {
        $(this).val('');
    });

	// when the Submit button is clicked...
	$('input#submit').click(function() {
	$('.error').hide().remove();
		//Inputed Strings
		var username = $('#name').val(),
			email = $('#email').val(),
			comment = $('#comment').val();
		
	
		//Error Count
		var error_count;
		
		//Regex Strings
		var username_regex = /^[a-z0-9_-]{3,16}$/,
			email_regex = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
		
			//Test Username
			if(!username_regex.test(name)) {
				$('#contact_header').after('<p class=error>Vous n avez pas specifie de nom!</p>');
				error_count += 1;
			}
			
			//Test Email
			if(!email_regex.test(email)) {
				$('#contact_header').after('<p class=error>Votre adresse e-mail est incorrecte!</p>');
				error_count += 1;
			}
			
			//Blank Comment?
			if(comment == '') {
				$('#contact_header').after('<p class=error>Veuillez laisser un message!</p>');
				error_count += 1;
			}
			
			//No Errors?
			if(error_count === 0) {
				$.ajax({
					type: "post",
					url: "send.php",
					data: "name=" + name + "&email=" + email + "&comment=" + comment,
					error: function() {
						$('.error').hide();
						$('#sendError').slideDown('slow');
					},
					success: function () {
						$('.error').hide();
						$('.success').slideDown('slow');
						$('form#contactForm').fadeOut('slow');
					}				
				});	
			}
			
			else {
                $('.error').show();
            }
			
		return false;
	});
	
});
Salut,

Je ne sais pas si ça explique tout, mais déjà :
if(!username_regex.test(name))
Ta variable s'appelle username, pas name.
J'ai bien changé mais rien n'y fait:
Je joint l'xhtml et le php, merci de votre aide.

[code=html]<div id="contact">
<div id="close">Fermer</div>
<div id="contact_header">Contact</div>
<p class="success">Merci. Votre message a bien été transmis</p>

<form action="html/send.php" method="post" name="contactForm" id="contactForm">
<p><input name="name" id="name" type="text" value="Votre nom" /></p>
<p><input name="email" id="email" type="text" value="Votre adresse e-mail" /></p>
<p><textarea name="comment" id="comment" rows="5" cols="40">Votre message...