Visualizzazione dei risultati da 1 a 8 su 8
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2007
    Messaggi
    179

    Invio del form sulla stessa pagina index.php

    Ciao a tutti.
    ho un problema con ajax, vorrei fare in modo che l'invio del form sta nella stessa pafina index.php e no in thank-you.php
    Ho trovato questo tutorial per imparare ma nn mi e' chiara ancora la parte su come devo mandare i valori che mi servono alla stessa pagina index.php
    Vi posto il codice
    codice:
    // AJAX
    function GetXmlHttpObject()
    {
    	if (window.XMLHttpRequest)
    	{
    		// IE7+, Firefox, Chrome, Opera, Safari
    		return new XMLHttpRequest();
    	}
    	
    	if (window.ActiveXObject)
    	{
    		// IE5, IE6
    		return new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	
    	return null;
    }
    
    function submitFormWithAjax()
    {
    	var ajaxRequest = new GetXmlHttpObject();
    
    	var checkFormSendMail = document.formSendMail.checkFormSendMail.value;
    	var sender = document.formSendMail.sender.value;
    	var sendTo = document.formSendMail.sendTo.value;
    	var subject = document.formSendMail.subject.value;
    	var textMessage = document.formSendMail.textMessage.value;
    	var captcha = document.formSendMail.captcha.value;
    
    	var parameters = "checkFormSendMail=" + checkFormSendMail + "&sender=" + sender + "&sendTo=" + sendTo + "&subject=" + subject + "&textMessage=" + textMessage
    						+ "&captcha=" + captcha;
    
    	ajaxRequest.open("POST", "index.php", true);
    	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    	ajaxRequest.send(parameters);
    	
    	ajaxRequest.onreadystatechange = function()
    	{
    		if (ajaxRequest.readyState == 4)
    		{
    			if (ajaxRequest.status == 200)
    			{
    				document.getElementById("divFormMail").innerHTML = ajaxRequest.responseText;
    			
    				//document.getElementById("divUploadFile").style.display = "none";
    			}
    			else
    			{
    				document.getElementById("divFormMail").innerHTML = "An error has occured making the request";
    			}
    		}
    		else
    		{
    			document.getElementById("divFormMail").innerHTML = '[img]img/Loading.gif[/img] Loading Content...';
    		}
    	}
    }
    // AJAX
    Provando il codice in questo modo funziona ma ho dentro il divFormMail l'intera pagina index.php duplicate e quindi ne vedo due una al centro e l'altra dato che sta' nel div un po' spostata a destra e in basso...
    Nn mi e' chiara sta parte
    codice:
    ajaxRequest.onreadystatechange = function()
    	{
    		if (ajaxRequest.readyState == 4)
    		{
    			if (ajaxRequest.status == 200)
    			{
    				document.getElementById("divFormMail").innerHTML = ajaxRequest.responseText;
    			
    				//document.getElementById("divUploadFile").style.display = "none";
    			}
    			else
    			{
    				document.getElementById("divFormMail").innerHTML = "An error has occured making the request";
    			}
    		}
    		else
    		{
    			document.getElementById("divFormMail").innerHTML = '[img]img/Loading.gif[/img] Loading Content...';
    		}
    	}
    Come faccio ad usare la stessa pagina index visto che le variabili POST stanno li? thanks!!

  2. #2
    Utente di HTML.it
    Registrato dal
    Apr 2007
    Messaggi
    179
    Raga dai nessuno di voi esperti sa darmi una mano? per voi e' na fesseria che gia' sapete io mi sto' dannando ad imparare da solo...uff help please!!

  3. #3
    Quel codice manda una richiesta alla pagina index.php e mette nel div la risposta che riceve... ma tu hai detto proprio che deve chiamare la pagina index.php, quindi non so come aiutarti. Se tu non vuoi che index.php compaia nel div probabilmente devi chiamare un'ALTRA pagina, ma io non conosco il tuo script.

  4. #4
    Utente di HTML.it
    Registrato dal
    Apr 2007
    Messaggi
    179
    Volevo appunto evitare di chiamare un' altra pagina...
    Vedo su internet molti siti che hanno la stessa pagina come ritorno li come fanno?
    E poi ho postato tutto lo script ajax quello .php nn e' altro che una pagina index con dentro il form html e sopra le variabili $_POST[' ']

  5. #5
    Utente di HTML.it
    Registrato dal
    Apr 2007
    Messaggi
    179
    Nothing? ... come devo fa' che sto' uscendo pazzo...
    Ho una pagina index.php con dentro il richiamo alla classe send mail con un new SendMail()
    Poi ho una pagina sendMail.php con un richiamo alla classe send mail con un altro new SendMail()
    Nel file index.js faccio indirizzare dal form di index.php a pagina sendMail.php e invia correttemente le variabili e sempre nel file index.js dico di nascondere il form in modo che mi visualizza il testo contenuto in sendMail.php (che nn e' altro che un echo delle variabili $_POST['']) al posto dei campi di input del fomr di pagina index.php
    Le mail le invia solo che in index.php ho un richiamo alla funziona toLog() della classe send mail...ma in index nn mi vede una mazza xke nn mi riconosce le variabili in toLog()..se invece metto toLog() nel file sendMail.php li funziona...ma poco mi serve xke nn riesco a piazzarlo nella index....sara' peche ho usato un new SendMail() in index.php e uno in success.php?
    Vi posto il codice delle due pagina php + il js e vi prego aiutatemi.....nn ci riesco da solo....

    index.php
    codice:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <?php
    require("db.php");
    require("Class/SendMail.class.php");
    
    $SendMail = new SendMail();
    ?>
    <html>
    	<head>
    		
    		<meta http-equiv="Pragma" content="no-cache"></meta>
    		<meta http-equiv="Expires" content="-1"></meta>
    		<meta http-equiv="Cache-Control" content="no-cache"></meta>
    		
    		<title><?php echo $siteName; ?></title>
    		<link rel="stylesheet" type="text/css" href="Css/Style1.css"></link>
    		<script src="Js/Index.js"></script>
    	</head>
    	<body>
    		<div id="divHeader">
    			<h1 id="hSiteName"><?php echo $siteName; ?></h1>
    		</div>
    		<div id="divCenter">
    			<div id="divInformation" class="overflow_scroll">
    				<h1 id="hInformation">Informazioni</h1>
    				<p id="pInformation">
    					<?php echo $SendMail->toInformation(); ?>
    				</p>
    			</div>
    			<div id="divLog" class="overflow_scroll">
    				<h1 id="hLog">Log</h1>
    				<p id="pLog">
    					<?php echo $SendMail->toLog(); ?>
    				</p>
    			</div>
    			<div id="divFormMail">
    				<form id="formSendMail" name="formSendMail">
    					<input type="hidden" name="checkFormSendMail" value="ok"></input>
    					
    					<p id="pSender">Mittente:</p>
    					<input id="inputSender" name="sender" value="" type="text" tabindex="1"></input>
    					<?php  ?>
    					
    					<p id="pTo">Destinatario / i:</p>
    					<input id="inputSendTo" name="sendTo" value="" type="text" tabindex="2"></input>
    					
    					<p id="pSubject">Soggetto:</p>
    					<input id="inputSubject" name="subject" value="" type="text" tabindex="3"></input>
    					
    					<p id="pMessage">Messaggio:</p>
    					<textarea id="textareaMessage" name="textMessage" value="" type="text" tabindex="4"></textarea>
    					
    					<p id="pCaptcha">Codice:</p>
    					<input id="inputCaptcha" name="captcha" value="" type="text" tabindex="5"></input>
    					[img]Captcha.php[/img]</img>
    					
    					<button id="buttonSend" name="buttonSend" type="button" onClick="submitFormWithAjax();" tabindex="6">Invia</button>
    					<button id="buttonReset" name="buttonReset" type="reset" tabindex="7">Reset form</button>
    				</form>
    				<button id="buttonReload" name="buttonReload" type="button" onClick="parent.location='<?php echo $siteUrl; ?>';" tabindex="8">Ricarica pagina</button>
    			</div>
    			<div id="divUploadFile">
    				<form id="formUploadFile" name="formUploadFile" method="POST" action="<?php echo $siteUrl . "/index.php"; ?>" enctype="multipart/form-data">
    					<input type="hidden" name="checkFormUploadFile" value="ok"></input>
    					
    					<p id="pUploadFile">Allegato:</p>
    					<input id="inputUploadFile" class="hidden" name="uploadFile" type="file" onChange="toNameUploadFile(this.value);"></input>
    					
    					<input id="inputUploadFileFake" name="inputUploadFileFake" value="Nessun allegato" type="text"></input>
    					<button id="buttonUploadFileFake" name="buttonUploadFileFake" type="button" onClick="toOpenUploadFile('inputUploadFile');" tabindex="9">Sfoglia</button>
    					
    					<button id="buttonAttach" name="buttonAttach" type="submit" tabindex="10">Allega</button>
    				</form>
    			</div>
    		</div>
    		<div id="divFooter">
    			<p id="pPowered">Powered by: <?php echo $poweredUrl; ?> - <?php echo $poweredMail; ?></p>
    		</div>
    	</body>
    </html>
    sendMail.php
    codice:
    <?php
    session_start();
    
    require("Class/SendMail.class.php");
    
    $SendMail = new SendMail();
    
    //$SendMail->toAttachment($_POST["checkFormUploadFile"], $_FILES["uploadFile"]["tmp_name"], $_FILES["uploadFile"]["name"], $_FILES["uploadFile"]["type"], $_FILES["uploadFile"]["size"]);
    
    //echo "checkFormSendMail: " . $_POST["checkFormSendMail"] . "
    ";
    //echo "sender: " . $_POST["sender"] . "
    ";
    //echo "sendTo: " . $_POST["sendTo"] . "
    ";
    //echo "subject: " . $_POST["subject"] . "
    ";
    //echo "textMessage: " . $_POST["textMessage"] . "
    ";
    //echo "captcha: " . md5($_POST["captcha"]) . " - " . $_SESSION['randomMd5'] . "
    ";
    
    $SendMail->toSend($_POST["checkFormSendMail"], $_POST["sender"], $_POST["sendTo"], $_POST["subject"], $_POST["textMessage"], $_POST["captcha"], $_SESSION['randomMd5']);
    ?>
    index.js
    codice:
    // AJAX
    function GetXmlHttpObject()
    {
    	if (window.XMLHttpRequest)
    	{
    		// IE7+, Firefox, Chrome, Opera, Safari
    		return new XMLHttpRequest();
    	}
    	
    	if (window.ActiveXObject)
    	{
    		// IE5, IE6
    		return new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	
    	return null;
    }
    
    function submitFormWithAjax()
    {
    	var ajaxRequest = new GetXmlHttpObject();
    
    	var checkFormSendMail = document.formSendMail.checkFormSendMail.value;
    	var sender = document.formSendMail.sender.value;
    	var sendTo = document.formSendMail.sendTo.value;
    	var subject = document.formSendMail.subject.value;
    	var textMessage = document.formSendMail.textMessage.value;
    	var captcha = document.formSendMail.captcha.value;
    
    	var parameters = "checkFormSendMail=" + checkFormSendMail + "&sender=" + sender + "&sendTo=" + sendTo + "&subject=" + subject + "&textMessage=" + textMessage
    						+ "&captcha=" + captcha;
    
    	ajaxRequest.open("POST", "SendMail.php", true);
    	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    	ajaxRequest.send(parameters);
    	
    	ajaxRequest.onreadystatechange = function()
    	{
    		if (ajaxRequest.readyState == 4)
    		{
    			if (ajaxRequest.status == 200)
    			{
    				document.getElementById("divFormMail").innerHTML = ajaxRequest.responseText;
    			
    				document.getElementById("divUploadFile").style.display = "none";
    			}
    			else
    			{
    				document.getElementById("divFormMail").innerHTML = "An error has occured making the request";
    			}
    		}
    		else
    		{
    			document.getElementById("divFormMail").innerHTML = '[img]img/Loading.gif[/img] Loading Content...';
    		}
    	}
    }
    // AJAX
    Vorrei fare in modo come detto sempre che premo su invia e in index mi fa vedere le variabili degli input del form...

  6. #6
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Studiati questa ottima guida
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  7. #7
    Utente di HTML.it
    Registrato dal
    Apr 2007
    Messaggi
    179
    Oki tra varie prove sono riuscito...
    solo che adesso rimane il fatto del captcha da refreshare se ci voglio cliccare o altro..
    Ho visto su internet che usano questo metodo...
    codice:
    [img]Captcha.php[/img]</img>
    ho capito che restituisce il tempo del browser in modo da avere sempre un numero diverso e dire che l'immagine nn e' piu' la stessa cosi' forzi il cambiamento ma a me nn funziona xke mi restituisce questo quando guardo il link dell' immagine -> /captcha.php&time=1290276324156
    Come fo' e nn mi dite di andare a gurdare guide per favore xke ho bisogno di spiegazioni seno' se capivo il perche' etc etc nn postavo di certo su un forum...thanks...

  8. #8
    Utente di HTML.it
    Registrato dal
    Apr 2007
    Messaggi
    179
    Risolto...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.