11548 sujets

JavaScript, DOM et API Web HTML5

Pages :
(reprise du message précédent)

Ca aurait été un problème pour la suite c'est sûr, merci Smiley biggrin .

Mais ça n'arrange pas le fait que mes champs ne soient pas vérifiés, tu ne sais pas d'où ça vient ?
Je le sors de mon script jQuery en GET dans "link" :


<script type="text/javascript">
		$(document).ready(function(){
			$('#regform input').ajaxify({
			        event:'change',
			        method:'POST',
			        loading_img:'images/loader.gif',
			        loading_txt:'Vérification...',
			        link:'formmail.php?action=regsubmit&ajax=true',
			        forms:'input'
			});
			$('#regform textarea').ajaxify({
			        event:'change',
			        method:'POST',
			        loading_img:'images/loader.gif',
			        loading_txt:'Vérification...',
			        link:'formmail.php?action=regsubmit&ajax=true',
			        forms:'textarea'
			});
			$('.check').ajaxify({
				event:'submit',
				link:'formmail.php?action=submit&ajax=true',
				forms:'.check',
				target:'#result',
				loading_img:'images/loader.gif',
				loading_txt:'Vérification...',
				method:'POST',
				animateOut:{'height':'toggle'},
				animateIn:{'height':'toggle'},
				onSuccess:function(o,data){
				$(o.target).html("<div class='success'><img src='images/check.png' alt='Succés'/> Votre message a bien été envoyé</div>");
				}
				});
		});
    </script>


C'est censé marcher non ? Smiley rolleyes
Ben en fait, j'ai un doute. Tu envoie des données via post et demande également des choses via GET. Tu aurais meilleur temps de coller un champ caché dans ton formulaire. UN bon vieux
input type="hidden"
des familles. Au moins, tu es sûr que tout post passe.
Puis tu peux faire une petite verif via un
print_r($_POST);
, histoire de voir si ton action="submit" est bien passé
Je vais tester ça mais je pense que la variable "action" passe puisque le traitement et l'envoi du mail se passe bien alors qu'un test if($_GET['action']=="submit") est requis pour effectuer cela. Smiley confus C'est à n'y rien comprendre...

Peut être devrais-je faire un autre sujet ?

Sinon, aurais-tu du code à me passer qui ferait la même chose, et surtout : QUI MARCHE Smiley langue !

Merci à toi
Modifié par coenonympha (04 Feb 2009 - 17:22)
Euh presque Smiley biggrin J'ai finalement changé de script !

Tout marche pour le mieux mis à part que : le mail ne part pas Smiley fache ...

Le script est censé marcher avec ou sans javascript.

Pourrais tu me dire ce qui ne va pas dans le fichier de traitement PHP car cela vient forcément de là...


<?php
// Change this to the page which holds the form.  The page needs to have the necessary php code 
// to handle non javascript responses for degradability.
$referringPage = 'http://www.lambda-comm.fr/contact.php';

// Change the recipients variable to determine where the email will be sent.  This is modified
// from Dagon Design's PHP Secure Form Mailer (http://www.dagondesign.com/articles/secure-php-form-mailer-script/)
// ----------
// One:       "onerecip|(email)"
// Multiple:  "mulrecip|(cc or bcc)|(email 1)|(email 2)  etc.. "
$recipients = "onerecip|(contact@lambda-comm.fr)";
// Change the form_structure variable to define the types of fields in your form.  This is modified
// from Dagon Design's PHP Secure Form Mailer (http://www.dagondesign.com/articles/secure-php-form-mailer-script/)
// field type | field label | field name/id (should be the same) | required? (true/false) | type of verification (none, email, url)
$form_structure = array(
	"text|Name|fm_name|true|none",
	"text|Email|fm_email|true|email",
	"textarea|Message|fm_message|true|none"
);
// Define the name, email and subject fields of your form.  If you keep the default "name" definitions in the HTML,
// this doesn't need to be edited.
$field_name = "fm_name";
$field_email = "fm_email";
$field_subject = "Contact Client";
// The subject that will appear in the email you receive.
$subject = 'Contact Client';
//Misc. Config Options
$show_headers_in_message = FALSE;
$wrap_messages = TRUE;
$include_ip = TRUE;
$msg_mailserver = "Impossible d'envoyer le message, veuillez réessayer ultérieurement";
$msg_sent = "Votre message a bien été envoyé.";
$msg_error = "Veuillez revenir à la page précédente pour corriger vos erreurs.";
// Do not edit anything below unless you know what you are doing [smile]
$email_sent = FALSE;
$t_out = "";
// turn $recipients into a useable array
$recipients = explode("|", $recipients);
for ($i = 0; $i < count($recipients); $i++) {
	$recipients[$i] = trim($recipients[$i]);
}
// turn form fields into a useable array
for ($i = 0; $i < count($form_structure); $i++) {
	$form_structure[$i] = explode("|", $form_structure[$i]);
	for ($j = 0; $j < count($form_structure[$i]); $j++) {
		$form_structure[$i][$j] = trim($form_structure[$i][$j]);
	}
}
// cleanup the post string
function cleanPosUrl ($str) {
	$nStr = $str;
	$nStr = str_replace("**am**","&",$nStr);
	$nStr = str_replace("**pl**","+",$nStr);
	$nStr = str_replace("**eq**","=",$nStr);
	return stripslashes($nStr);
}
function is_valid_url($link) { 
// returns TRUE if url actually exists
	if (strpos($link, "http://") === FALSE) { $link = "http://" . $link; }
    $url_parts = @parse_url($link);
	if (empty($url_parts["host"])) return( false );
	if (!empty($url_parts["path"])) { $documentpath = $url_parts["path"]; } 
    else { $documentpath = "/"; }
	if (!empty($url_parts["query"])) { $documentpath .= "?" . $url_parts["query"]; }
	$host = $url_parts["host"];	$port = $url_parts["port"];
	if (empty($port)) $port = "80";
	$socket = @fsockopen( $host, $port, $errno, $errstr, 30 );
	if (!$socket) {	return(false); } 
    else {fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n");
	$http_response = fgets( $socket, 22 );
	if (ereg("200 OK", $http_response, $regs)) { return(true); fclose($socket);	} 
	else { return(false); } }
}
function is_valid_email($email) {
// returns TRUE if email address is valid
	$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
	$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
	$atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
		'\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
	$quoted_pair = '\\x5c[\\x00-\\x7f]';
	$domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
	$quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
	$domain_ref = $atom;
	$sub_domain = "($domain_ref|$domain_literal)";
	$word = "($atom|$quoted_string)";
	$domain = "$sub_domain(\\x2e$sub_domain)*";
	$local_part = "$word(\\x2e$word)*";
	$addr_spec = "$local_part\\x40$domain";
	return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
}
function injection_chars($s) {
// returns TRUE if 'bad' characters are found
	return (eregi("\r", $s) || eregi("\n", $s) || eregi("%0a", $s) || eregi("%0d", $s)) ? TRUE : FALSE;
}
function strip_colons($s) {
	return str_replace(array(':', '%3a'), " ", $s);
}
if (isset($_POST["form_submitted"])) {
// if the form has been submitted
	// prepare error list
	unset($errors);
	// prepare mail variables
	$mail_message = "";
	$mail_name = "Anonyme";
	$mail_subject = $subject;
	$mail_email = 'anonyme@inconnu.com';
	// process input
	foreach ($form_structure as $form_field) {
	switch ($form_field[0]) {
	case "text":
	case "password":
		$f_type = $form_field[0];
		$f_name = $form_field[1];
		$f_fmname = $form_field[2];
		$f_req = $form_field[3];
		$f_ver = $form_field[4];
		// get data
		$t = (isset($_POST[$f_fmname])) ? trim($_POST[$f_fmname]) : "";
		if (get_magic_quotes_gpc()) {
			$t = stripslashes($t);
		}
		// check for required fields
		if (($f_req == "true") && ($t == "")) {
			if ($f_fmname != $field_verification) { // has it's own check
				$errors[] = "Vous n'avez pas rempli ce champ : '$f_name'.";
			}
		}
		// check for injection characters
		if (($f_type != "textarea") && (injection_chars($t))) {
			$errors[] = "Contenu incorrect dans '$f_name'!";
		}
		// check for valid email (if present/required)
		if (($f_ver == 'email') && ($f_req == "true" || (trim($t) != ""))) {
			if (!is_valid_email($t)) {
				$errors[] = "Adresse E-mail non valide : '$f_name'";
		//comment this out if your host has problems with the mxrecord check
			}
		}
		// check for valid url (if present/required)
		if (($f_ver == 'url') && ($f_req == "true" || (trim($t) != ""))) {
			if (!is_valid_url($t)) {
				$errors[] = "Adresse internet non valide : '$f_name'";
			}
		}
		// check for headers/verification fields
		if ($f_fmname == $field_name) {
			if ($t != "") {
				$mail_name = strip_colons($t);
				if ($show_headers_in_message)
					$mail_message .= $f_name . ' = ' . $t . "\n\n";
			}
		} elseif ($f_fmname == $field_subject) {
			if ($t != "") {
				$mail_subject = $subject . strip_colons($t);
				if ($show_headers_in_message)
					$mail_message .= $f_name . ' = ' . $t . "\n\n";
			}
		} elseif ($f_fmname == $field_email) {
			if ($t != "") {
				$mail_email = strip_colons($t);
				if ($show_headers_in_message)
					$mail_message .= $f_name . ' = ' . $t . "\n\n";
			}
		} else {
			if ($t != "") {
				$mail_message .= $f_name . ' = ' . $t . "\n\n";
			}
		}
		break;
	case "textarea":
		$f_name = $form_field[1];
		$f_fmname = $form_field[2];
		$f_req = $form_field[3];
		// get data
		$t = (isset($_POST[$f_fmname])) ? trim($_POST[$f_fmname]) : "";
		if (get_magic_quotes_gpc()) {
			$t = stripslashes($t);
		}
		// check for required fields
		if (($f_req == "true") && ($t == "")) {
			if ($f_fmname != $field_verification) { // has it's own check
				$errors[] = "Champ requis non rempli : '$f_name'.";
			}
		}
		if ($t != "") {
			$mail_message .= $f_name . " = \n" . $t . "\n\n";
		}
		break;
	case "checkbox":
		$f_name = $form_field[2];
		$t_message = $f_name . ' =';
		$f = FALSE;
		for ($i = 3; $i < count($form_field); $i+=3) {
			$f_fmname = $form_field[$i];
			$f_caption = $form_field[$i+1];
	
			$t = (isset($_POST[$f_fmname])) ? trim($_POST[$f_fmname]) : "";
			if ($t == 'on') {
				$t_message .= " " . $f_caption . ","; 
				$f = TRUE;
			}
		}
		$t_message = rtrim($t_message, ',');
		if ($f) {
			$mail_message .= $t_message . "\n\n";
		}
		break;
	case "radio":
		$f_name = $form_field[2];
		$f_fmname = $form_field[3];
		$t = (isset($_POST[$f_fmname])) ? trim($_POST[$f_fmname]) : "";
		$f = FALSE;
		for ($i = 5; $i < count($form_field); $i+=2) {
			if ($t == $form_field[$i]) {
				$f = TRUE;
			}
		}
		if ($f) {
			$mail_message .= $f_name . ' = ' . $t . "\n\n";
		}
		break;
	case "select":
		$f_name = $form_field[2];
		$f_fmname = $form_field[3];
		$t_message = $f_name . ' =';
		$t = (isset($_POST[$f_fmname])) ? $_POST[$f_fmname] : "";
		foreach ((array)$t as $tt) {
			$f = FALSE;		
			for ($i = 6; $i < count($form_field); $i++) {
				if (($form_field[$i] == $tt) && (trim($tt) != "")) {
					$f = TRUE;
				}
			}
			if ($f) {
				$t_message .= ' ' . $tt . ',';
			}
		}
		$t_message = rtrim($t_message, ',');
		if ($f) {
			$mail_message .= $t_message . "\n\n";
		}
		break;
	}
	}
// If there are more than the default fields (name, email, subject, message, submit button), parses extra fields and returns "name: value" pairs in the body of the email
function echoOthers() {
	$totalposted = count($_POST);
	$others = '';
	if ($totalposted > 4) {
		unset($_POST['fm_message']);
		unset($_POST['fm_name']);
		unset($_POST['fm_email']);
		unset($_POST['form_submitted']);
		foreach($_POST as $name => $value) {
			$others .= "\n";
			$others .= $name . ": " . $value;
		}
	}
	return $others;
}
	// if no errors, process
	if (empty($errors)) {
		$mail_message .= echoOthers();
		$mail_message = trim($mail_message);
		// wrap messages if set
		if ($wrap_messages) {
			$mail_message = wordwrap($mail_message, 70);
		}
		// prepare the headers
		// \r\n seems to be the best method for most servers to handle
		$ip = $_SERVER["REMOTE_ADDR"];
		$mail_header = "";
		$mail_header .= "MIME-Version: 1.0\r\n"; 
		$mail_header .= "X-Sender-IP: $ip\r\n";
		$mail_header .= "Content-Type: text/plain\r\n";
		$mail_header .= "From: " . $mail_name . " <" . $mail_email . ">";
		if ($recipients[0] == 'onerecip') {

			$mail_to = $recipients[1];

		} elseif ($recipients[0] == 'mulrecip') {

			$mail_to = $recipients[2];
			for ($i = 3; $i < count($recipients); $i++) {

				$mail_header .= "\r\n";
				if ($recipients[1] == 'cc') {
					$mail_header .= "Cc: ";
				} else {
					$mail_header .= "Bcc: ";
				}
				$mail_header .= $recipients[$i];
			}
		} elseif ($recipients[0] == 'selrecip') {
			$recip_number = (int)$_POST[$field_dropdownrecip];
			foreach ($form_structure as $form_field) {
				if ($form_field[0] == 'selrecip') {
					$j = 1;
					for ($i = 4; $i < count($form_field); $i++) {
						if (strpos($form_field[$i], "#") === 0) {
							$i++;
						}
						$i++;
						if ($recip_number == $j) {
							$mail_to = $form_field[$i];
						}
						$j++;
					}
				}
			}
		} 
		// send mail, setting $email_sent to true or false
		if (mail($mail_to, $mail_subject, $mail_message, $mail_header)) {
			$email_sent = true; 
		} else {
			$errors[] = $msg_mailserver;
			$email_sent = false;
		}

	}
	if (isset($errors)) {
		// if there were errors, list them
		$t_out .= 'Erreur (';
		foreach ($errors as $f)
			$t_out .= ' ' . $f . '  ';

		$t_out .= ')';
		$posStatus = 'NOTOK'; $posConfirmation = $t_out;

	} else {

		// the message was sent, display message


		$posStatus = 'OK'; $posConfirmation = $msg_sent;

	}
	



}

// replaces newlines with **nl** for better xml transfer.  Decoded at other end.
function nl2brr($text) {
	return preg_replace("/\r\n|\n|\r/", "**nl**", $text);
}

if ( $_GET['contact'] == true && $_GET['xml'] == true ) {
	//return xml
	header('Content-Type: application/xml');
	echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
	
	echo '<resultset>';
	
	echo '
			<status>'.$posStatus.'</status>
			<confirmation>'.$posConfirmation.'</confirmation>
			<regarding>'.$mail_subject.'</regarding>
			<name>'.$mail_name.'</name>
			<email>'.$mail_email.'</email>
			<message>'.nl2brr($mail_message).'</message>
			';
	
	echo'	</resultset>';
} else if ($posStatus == "OK" ) {
	// if called without javascript, return success to the referring page
	header('Location: '.$referringPage.'?success=true');
} else {
	// if called without javascript, return error to the referring page
	if (isset($errors)) {

		// if there were errors, list them

		$t_out = '<h2 style="color:red;">Erreur (';
				
		foreach ($errors as $f)
			$t_out .= ' ' . $f . '  ';

		$t_out .= ')</h2><br />';
		$t_out .= '<h3>'.$msg_error.'</h3>';
		echo $t_out;

	}	
	}
?>


J'espère que ça ne t'embête pas mais là, je ne vois pas d'où cela peut venir ... Smiley confus
Pages :