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
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Line Breaks Deleted When Passing Variables

    Hello, I have been having issues when passing form variables(specifically the textarea) to a php script using the code below. My issue is that all line breaks and extra white space are deleted. It seems my trouble stems from the fact that I'm using GET in my javascript versus POST.

    I was wondering if someone had a smart way to convert my javascript to use POST, or if there is another method to do this?

    Thanks for any and all insight in advance!


    Javascript:
    Code:
    <script language="javascript" type="text/javascript">
    
    //Browser Support Code
    function submitReview(watchid){
     var ajaxRequest;  // The variable that makes Ajax possible!
     	
     try{
       // Opera 8.0+, Firefox, Safari
       ajaxRequest = new XMLHttpRequest();
     }catch (e){
       // Internet Explorer Browsers
       try{
          ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
       }catch (e) {
          try{
             ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
          }catch (e){
             // Something went wrong
             alert("Your browser broke!");
             return false;
          }
       }
     }
     // Create a function that will receive data 
     // sent from the server and will update
     // div section in the same page.
     ajaxRequest.onreadystatechange = function(){
       if(ajaxRequest.readyState == 4){
          var newtext = "Your review has been submitted to the moderator for approval.";
          document.getElementById('reviewform').innerHTML = newtext;
         }
     }
     // Now get the value from user and pass it to
     // server script.
     var id = document.getElementById('id').value;
     var brand = document.getElementById('brand').value;
     var ovr = document.getElementById('ovr').value;
     var bld = document.getElementById('bld').value;
     var erg = document.getElementById('erg').value;
     var val = document.getElementById('val').value;
     var com = document.getElementById('com').value.replace(/\n/g,'<br />');
     var len = document.getElementById('len').value;
     var use = document.getElementById('use').value;
     var un = document.getElementById('un').value;
     var mdy = document.getElementById('mdy').value;
     var ytURL = document.getElementById('ytURL').value;
     var price = document.getElementById('price').value; 
    
    
     var queryString = "?id=" + id ;
     queryString +=  "&brand=" + brand + "&ovr=" + ovr + "&bld=" + bld + "&erg=" + erg + "&val=" + val + "&com=" + com + "&len=" + len + "&use=" + use + "&un=" + un + "&mdy=" + mdy + "&price=" + price + "&ytURL=" + ytURL;
     ajaxRequest.open("GET", "sendreview.php" + 
                                  queryString, true);
     ajaxRequest.send(null); 
    
    
    
    }
    
    </script>

    *EDIT* I figured this out. I added the code in red and then converted it back with a preg_replace in the PHP.
    Last edited by uparmored; 02-19-2012 at 01:13 AM.

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    I see that you have already sorted out the line break issue, but to answer your question regarding the use of POST rather than GET for your AJAX, take a closer look at this part:

    Code:
     ajaxRequest.open("GET", "sendreview.php" + 
                                  queryString, true);
     ajaxRequest.send(null);
    You might be able to guess what needs to be changed there to get rolling with a POST request.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting


  •  

    Posting Permissions

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