Page 1 sur 1

Prob avec formulaire

Posté : 04 avr. 2007, 17:03
par polak25
Bonjour a tous,

j'ai un probleme pour un formulaire.

En faite, j'utilise dans mon site le script "Ajax dynamic content script" telechargeable a l'adresse http://www.dhtmlgoodies.com/index.html? ... ic-content

Mais le probleme quand j'envoie avec un formulaire, mes variables $_POST ne passe pas, voici ma page :


Code : Tout sélectionner

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Pharm-Upp.com</title> <link type="text/css" href="css/style.css" rel="stylesheet" media="screen" /> <script type="text/javascript" src="js/autocompletation.js"></script> <script type="text/javascript" src="js/ajax.js"></script> <script type="text/javascript" src="js/ajax-dynamic-content.js"></script> </head> <body> <div id="page"> <div id="menu"> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="750" height="200" id="menu"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="swf/menu.swf" /> <param name="menu" value="false" /> <param name="quality" value="best" /> <param name="scale" value="exactfit" /> <param name="bgcolor" value="#ffffff" /> <embed src="swf/menu.swf" menu="false" quality="best" scale="exactfit" bgcolor="#ffffff" width="750" height="200" name="menu" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object> <noembed><a href="http://www.macromedia.com/go/getflash/">Si le menu ne s'affiche pas correctement, vous aurez besoin du plug-in Flash 8 ou +</a>.</noembed> </div> <div id="connexion"> <form method="post" name="pharm_ville" id="pharm_ville" action="javascript:ajax_loadContent('contenuDiv','recherche.php');"> Rechercher la pharmacie de votre commune : <input type="text" name="ville" id="ville" value="" size="40" autocomplete="off" /> <input type="submit" value="" name="submit" class="recherche" id="submit" /> </form> </div> <div id="contenuDiv">En cours de chargement ...</div> <div id="bas"><a href="http://www.e-maginair.com" target="_blank"><img src="images/copyright.gif" border="0"></a></div> </div> <script type="text/javascript"> ajax_loadContent('contenuDiv','accueil.php'); </script> </body> </html>
Merci de m'aider, je cherche depuis pas mal de tps

Posté : 04 avr. 2007, 17:30
par Cyrano
Modération :
polak25, le multipostage est interdit sur le forum.

Merci de prendre le temps de lire les règlements.

Posté : 04 avr. 2007, 17:31
par polak25
Dsl les gars, je ne le referais plus jamais, promis lol

Posté : 04 avr. 2007, 17:36
par Cyrano
Pour info, ceci :

Code : Tout sélectionner

action="javascript:ajax_loadContent('contenuDiv','recherche.php');"
N'est pas vraiment conforme : la valeur de cet attribut devrait être une url pointant vers la page de traitement.

Si tu veux effectuer un traitement AJAX, alors dans ce cas, ajoute un attribut "onsubmit" avec cette valeur-là et suivie d'un return false; pour empêcher le chargement de l'autre page, donc quelque chose comme :

Code : Tout sélectionner

action="./recherche.php" onsubmit="ajax_loadContent('contenuDiv','recherche.php'); return false;"

Posté : 04 avr. 2007, 17:37
par Hywan
Bon alors les variables $_POST prennent effet (sont créées) en début de page.
Avec Ajax, tu ne rafraîchis pas ta page, mais juste une partie de la page.
Donc c'est normal que ça ne fonctionne pas.

La question que je pose maintenant est : « Peut-on capturer les variables $_POST avec Ajax à la volée ? »

Ou peut-être que tu devrais rafraîchir la page, mais conserver tes paramètres Ajax pour afficher la page dans le même état. Je ne sais pas comment fonctionne le script.

Regardes du côté de Google ... :)

Posté : 04 avr. 2007, 17:50
par polak25
Dsl Cyrano mais cela ne marche pas,

la variables $_POST ne passe pas dans la page recherche.php

Posté : 04 avr. 2007, 18:06
par Cyrano
Alors il faudrait voir ton code JavaScript de récupération, c'est à ce niveau-là que ça bafouille. Je pourrai plus te répondre ce soir, mais d'autres passeront sûrement.

Posté : 04 avr. 2007, 18:09
par polak25
Alors voici les fichiers js :

ajax.js ==>

Code : Tout sélectionner

function sack(file) { this.xmlhttp = null; this.resetData = function() { this.method = "POST"; this.queryStringSeparator = "?"; this.argumentSeparator = "&"; this.URLString = ""; this.encodeURIString = true; this.execute = false; this.element = null; this.elementObj = null; this.requestFile = file; this.vars = new Object(); this.responseStatus = new Array(2); }; this.resetFunctions = function() { this.onLoading = function() { }; this.onLoaded = function() { }; this.onInteractive = function() { }; this.onCompletion = function() { }; this.onError = function() { }; this.onFail = function() { }; }; this.reset = function() { this.resetFunctions(); this.resetData(); }; this.createAJAX = function() { try { this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e1) { try { this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { this.xmlhttp = null; } } if (! this.xmlhttp) { if (typeof XMLHttpRequest != "undefined") { this.xmlhttp = new XMLHttpRequest(); } else { this.failed = true; } } }; this.setVar = function(name, value){ this.vars[name] = Array(value, false); }; this.encVar = function(name, value, returnvars) { if (true == returnvars) { return Array(encodeURIComponent(name), encodeURIComponent(value)); } else { this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true); } } this.processURLString = function(string, encode) { encoded = encodeURIComponent(this.argumentSeparator); regexp = new RegExp(this.argumentSeparator + "|" + encoded); varArray = string.split(regexp); for (i = 0; i < varArray.length; i++){ urlVars = varArray[i].split("="); if (true == encode){ this.encVar(urlVars[0], urlVars[1]); } else { this.setVar(urlVars[0], urlVars[1]); } } } this.createURLString = function(urlstring) { if (this.encodeURIString && this.URLString.length) { this.processURLString(this.URLString, true); } if (urlstring) { if (this.URLString.length) { this.URLString += this.argumentSeparator + urlstring; } else { this.URLString = urlstring; } } // prevents caching of URLString this.setVar("rndval", new Date().getTime()); urlstringtemp = new Array(); for (key in this.vars) { if (false == this.vars[key][1] && true == this.encodeURIString) { encoded = this.encVar(key, this.vars[key][0], true); delete this.vars[key]; this.vars[encoded[0]] = Array(encoded[1], true); key = encoded[0]; } urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0]; } if (urlstring){ this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator); } else { this.URLString += urlstringtemp.join(this.argumentSeparator); } } this.runResponse = function() { eval(this.response); } this.runAJAX = function(urlstring) { if (this.failed) { this.onFail(); } else { this.createURLString(urlstring); if (this.element) { this.elementObj = document.getElementById(this.element); } if (this.xmlhttp) { var self = this; if (this.method == "GET") { totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString; this.xmlhttp.open(this.method, totalurlstring, true); } else { this.xmlhttp.open(this.method, this.requestFile, true); try { this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") } catch (e) { } } this.xmlhttp.onreadystatechange = function() { switch (self.xmlhttp.readyState) { case 1: self.onLoading(); break; case 2: self.onLoaded(); break; case 3: self.onInteractive(); break; case 4: self.response = self.xmlhttp.responseText; self.responseXML = self.xmlhttp.responseXML; self.responseStatus[0] = self.xmlhttp.status; self.responseStatus[1] = self.xmlhttp.statusText; if (self.execute) { self.runResponse(); } if (self.elementObj) { elemNodeName = self.elementObj.nodeName; elemNodeName.toLowerCase(); if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea") { self.elementObj.value = self.response; } else { self.elementObj.innerHTML = self.response; } } if (self.responseStatus[0] == "200") { self.onCompletion(); } else { self.onError(); } self.URLString = ""; delete self.xmlhttp['onreadystatechange']; self.xmlhttp=null; self.responseStatus=null; self.response=null; self.responseXML=null; break; } }; this.xmlhttp.send(this.URLString); } } }; this.reset(); this.createAJAX(); }
ajax-dynamic-content.js ==>

Code : Tout sélectionner

var enableCache = true; var jsCache = new Array(); var dynamicContent_ajaxObjects = new Array(); function ajax_showContent(divId,ajaxIndex,url){ var targetObj = document.getElementById(divId); targetObj.innerHTML = dynamicContent_ajaxObjects[ajaxIndex].response; if(enableCache){ jsCache[url] = dynamicContent_ajaxObjects[ajaxIndex].response; } dynamicContent_ajaxObjects[ajaxIndex] = false; ajax_parseJs(targetObj) } function ajax_loadContent(divId,url){ if(enableCache && jsCache[url]){ document.getElementById(divId).innerHTML = jsCache[url]; ajax_parseJs(document.getElementById(divId)) evaluateCss(document.getElementById(divId)) return; } var ajaxIndex = dynamicContent_ajaxObjects.length; document.getElementById(divId).innerHTML = '<div align="center"><br /><br /><img src="images/ajax-loader.gif"><br />Page en cours de chargement<br /><br />'; dynamicContent_ajaxObjects[ajaxIndex] = new sack(); dynamicContent_ajaxObjects[ajaxIndex].requestFile = url; dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent(divId,ajaxIndex,url); }; dynamicContent_ajaxObjects[ajaxIndex].runAJAX(); } function ajax_parseJs(obj){ var scriptTags = obj.getElementsByTagName('SCRIPT'); var string = ''; var jsCode = ''; for(var no=0;no<scriptTags.length;no++){ if(scriptTags[no].src){ var head = document.getElementsByTagName("head")[0]; var scriptObj = document.createElement("script"); scriptObj.setAttribute("type", "text/javascript"); scriptObj.setAttribute("src", scriptTags[no].src); }else{ if(navigator.userAgent.toLowerCase().indexOf('opera')>=0){ jsCode = jsCode + scriptTags[no].text + '\n'; }else{ jsCode = jsCode + scriptTags[no].innerHTML; } } } if(jsCode)ajax_installScript(jsCode); } function ajax_installScript(script){ if (!script) return; if (window.execScript){ window.execScript(script) }else if(window.jQuery && jQuery.browser.safari){ window.setTimeout(script,0); }else{ window.setTimeout( script, 0 ); } } function evaluateCss(obj){ var cssTags = obj.getElementsByTagName('STYLE'); var head = document.getElementsByTagName('HEAD')[0]; for(var no=0;no<cssTags.length;no++){ head.appendChild(cssTags[no]); } }