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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Forum Validation Help Please

    I'm having some struggles with form validation. I dont have a problem sending the request and receiving the response, but I am having a problem making it either submit or dont submit based on the outcome.

    What I am trying to do, is for the user to clicks submit, which fires off the javascript request to ajax_info.php. If that file decides everything is AOK then there will be an empty response, in which case the function should return true and the submit should continue. If there is a response string, then notify the user via alert, and return false so the submit doesnt process.

    The only way the alert is happening is if I return false at the end of the javascript function. But if I do that, then the submit never happens. If I put it anywhere else, I dont get the alert (as though the response string is empty, even if it is not), and the submit proceeds regardless of the response.

    I hope I am making sense. Thanks.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    
    function loadXMLDoc()
    {
    
    var user = document.getElementById('username2').value;
    
    var xmlhttp;
    
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    
    xmlhttp.onreadystatechange=function()
      {
    
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
       	alert(xmlhttp.responseText);
    	return false;
        }
      else
        {
         return true;
        }
      }
    xmlhttp.open("GET","ajax_info.php?name=" + user + "&eml=fakemail@gmail.com&ref=filler",true);
    xmlhttp.send();
    
    }
    
    </script>
    </head>
    <body>
    
    
    <form action='fbauthorize.php' method='post' name='fbform' onsubmit="return loadXMLDoc();">
    				<center><big><big><b>Please Enter An Account Name:</big><br>
    				<input type='text' name='username' id='username'><br><br>
    				<input type='submit' value='Create Account'></form>
    
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    The very first line in your js kills the function
    var user = document.getElementById('username2').value;
    You have no username2 ID. But you have a username ID. Maybe a misprint?

    BUT Biggest question is "Why come back from ajax_info.php to submit again to the server? Why not have ajax_info.php call fbauthorize.php? Or just include the code of fbauthorize.php into ajax_info.php and make the alert(xmlhttp.responseText) say Mission accomplished data stored.'"?

  • #3
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're right about the username2. I admit I threw together the example based on everything I'd been doing and ultimately the username2 isnt the root of the problem I'm asking for help on. So yea, thanks for pointing that out, but we can ignore it for the moment.

    The reason I cannot create the account on ajax_info.php is because that page isnt being directly access by the user, so the Adwords conversion tracking code that needs to go at time of creation would not register the conversion properly.


  •  

    Posting Permissions

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