Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help to complete my newsletter form ajax call :) plzzzzz

    hi guys, i just diuscovered your site, i would like to ask you some help,
    about an ajax request i have to do on my site,
    its for my newletter.

    i am pretty sure my error is so ridiculous, hihihiiiiii
    but i really cannot fint how to correct my scrfipt, booooooooooooooo ))))))


    so here we go :

    MY FORM :

    Code:
    <form method="GET">
    <div id="newsletter_output">
    <div id="newsletter_content"></div>
    <div class="newsletter_close" onclick="newsletter_hide()">X</div>
    </div>
    
    <label for="saisissez_email"><span>Newsletter</span> Abonnez-vous à notre lettre d'info :</label>
    <div class="row"><label for="saisissez_email">Saisissez votre e-mail</label>
    
    <input name="email" type="text" id="saisissez_email"
     onclick="this.select();" class="text" value="">&nbsp;
    <div id="newsletter_buttons">
    <div  style="cursor:pointor;"
     onclick="TINY.ajax.call('a_ajax_subscribe_newsletter.php', 'newsletter_content', 'newsletter_display(\'newsletter_red\')')">
    <img src="images/btn_ok_violet.png" alt="ok"></div>
    </div>
    
     </div>
    </form>
    my script : its the famous tiny ajax one, just a few customized in order to get my email form field value :


    Code:
    TINY={};
    
    function T$(id){return document.getElementById(id)}
     
    
     
    TINY.ajax=function(){
        return{
            call:function(u,d,f,p){
    
    
    		
    		var x=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
    
    	var useremail = document.getElementById('saisissez_email').value;		
    
    		x.onreadystatechange=function(){
                    if(x.readyState==4&&x.status==200){
                        if(d){
                            var t=T$(d);
                            t.innerHTML=x.responseText
                        }
                        if(f){
                            var c=new Function(f); c()
                        }
                    }
                };
    			
    			
    	
    	
                if(p){
                    x.open('POST',u,true);
                    x.setRequestHeader('Content-type','application/x-www-form-urlencoded');
                    x.send(p)
                }else{
    			
    			
    		
    			
                    x.open('GET',u + '?email="+useremail"',true);
    				
    
    				
                    x.send(null)
                }
            }
        };
    }();
    
    function newsletter_display(name){
    	var newsletter_output=T$('newsletter_output');
    	newsletter_output.style.display='block';
    	newsletter_output.className=name;
    }
    
    function newsletter_hide(){
    	var newsletter_output=T$('newsletter_output');
    	newsletter_output.style.display='none';
    }


    and the ajax file called : a_ajax_subscribe_newsletter.php

    Code:
    <?php
    header("Content-Type: text/html; charset=UTF-8");
    
    //define('ATSPHP', 1);//REMOVE ONCE ALL PLUGINS ARE UPDATED
    define('SAFRANA', 1);
    $CONF = array();
    $FORM = array();
    $TMPL = array();
    // Change the path to your full path if necessary
    $CONF['path'] = '.';
    // Connect to the database
    // Set the last argument of $DB->connect to 1 to enable debug mode
    require_once("{$CONF['path']}/settings_sql.php");
    require_once("{$CONF['path']}/sources/sql/{$CONF['sql']}.php");
    
    //$email = $_GET['email'];
    //$email=htmlspecialchars($_GET['email']);
    $email = mysql_real_escape_string($_GET["email"]);
    
    //echo "verif01 = ok ... following ...";
    
    //if($_GET['subscribe'] = "true") {
    
    //$email = "{$email}";
    
    if($email != "") {
    //$email = mysql_real_escape_string($_GET['email']);
    $newsletter_msg = "ok, we got your email, database check ...";
    }
    else {
    $newsletter_msg = "at least, enter an email adress,<br /> tsss tsss lol, :)";
    //$TMPL['newsletter_msg'] = "at least, enter an email adress, tsss tsss lol, :)";
    }
    echo $email;
    
    $sqlCheckAgainst = "SELECT * FROM newsletterdb WHERE email='$email'";
    
    $result = mysql_query($sqlCheckAgainst);
    
    if ($result) {
    $newsletter_msg .= "<br />Error : email already in database";
    }
    else {
    //echo 'failure: ' . mysql_error();
    $newsletter_msg .= "<br />OK, email not found, <br />following on step 2 ...";
    }
    
    $notfound = true;
    
    while($row = mysql_fetch_array($result)) {
    	
    	if($row['email'] == $email) {
    		$notfound = false;
    		$newsletter_msg .= "<br />you've already subscribe to our newsletter !";
    	}
    }
    
    if($notfound == "true") {
    		
    	$setupdate = "INSERT INTO newsletterdb SET email='$email'";
    	
    	if (mysql_query($setupdate)) {
    		$newsletter_msg .= "ok, yes email added !";
    	}
    	
    	else {
    	
    	$newsletter_msg .= "nope, we had a trouble<br /> updating the db,<br />plz come back later ... !";
    		//echo 'failure: ' . mysql_error();
    	}
    	
    	
    }
    
    echo $newsletter_msg;
    
    
    //}//subscribe = true
    ?>
    would you please, help me guys ?

    see u guys, am around here )))))))))))))))))

  • #2
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the trouble is so simple : i do not succeed to pass my email var to my ajax file, grrrrr
    its quite stupide error, but its about a big site i hardly worked on,
    full of html5 & css3, utf-8 compliant.
    yesterday i succeeded to get the W3C certification, heheeeee i was so so happy,
    but there are a few stuff i have to finish, have a look at my site oif you get time :

    http://www.safran-du-petit-louvre.net

    the newletter zone is on the footer, wich still need more design, but from time to time, hihiiiii i will do it )))


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •