Values from a form replacing spaces with a "+"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aqualuvaro
    New Member
    • Jul 2008
    • 2

    Values from a form replacing spaces with a "+"

    Hi all,
    In advance, thanks for any help. I'm an absolute newbie to javascript so any help is much appreciated.

    (see code below) I have two html pages, form values are entered into one & displayed on the other, however, the spaces between words are showing as a plus sign instead.

    Any idea how to fix this so they are just spaces & not plus signs?

    Thanks!!

    Code:
    function callinput(key) 
    { 
    if(window.location.href.indexOf(key+'=')!=-1) 
    { 
    a=window.location.href.split("?")[1].split(key+"=")[1].split("&")[0]; 
    
    <!--cleanup data--> 
    a=unescape(a); 
    a=a.replace(/\+/," "); 
    
    
    document.write(a); 
    } 
    else 
    { 
    alert("Not all fields were filled. Please re-enter them."); 
    history.go(-1); 
    } 
    } 
    //-->
    and this is the code that "gets" the value (I think??)
    Code:
    script language="javascript" type="text/javascript">
     
    <!-- 
    callinput("store") 
    //--> 
    </script>
  • rohypnol
    New Member
    • Dec 2007
    • 54

    #2
    Simple:
    Use a <form> tag with method="POST" in the parent page and do a server-side check. Have the server decide if the fields were entered correctly or not and then redirect the user using the "Location" header. You should also do the check on the client, prior to submitting the form (in it's onsubmit event) and warn the user about errors and prevent the page from submitting. If you do this, you MUST still do server-side checks because JavaScript is easy to hack and anyone could submit wrong information to your server.

    Complicated:
    If you must stick to JavaScript and method="GET" for this kind of check, use a piece of JavaScript that encodes all the fields prior to sending the form (ie, in the form's onsubmit event) and then decode them when you read them right after line 5. You could use this script http://www.webtoolkit.info/javascript-base64.html and call it like so:
    Code:
    formElement.value = Base64.encode(formElement.value); // in the onsubmit event of the previous page
    a = Base64.decode(a); // in the [I]callinput()[/I] function you just pasted
    Also, don't forget to decode the fields on the server side if you're processing them somehow, I'm not aware of any server-side scripting language that doesn't implement some way to decode base64-encoded values.

    Comment

    • aqualuvaro
      New Member
      • Jul 2008
      • 2

      #3
      Originally posted by rohypnol
      Simple:
      Use a <form> tag with method="POST" in the parent page and do a server-side check. Have the server decide if the fields were entered correctly or not and then redirect the user using the "Location" header. You should also do the check on the client, prior to submitting the form (in it's onsubmit event) and warn the user about errors and prevent the page from submitting. If you do this, you MUST still do server-side checks because JavaScript is easy to hack and anyone could submit wrong information to your server.

      Complicated:
      If you must stick to JavaScript and method="GET" for this kind of check, use a piece of JavaScript that encodes all the fields prior to sending the form (ie, in the form's onsubmit event) and then decode them when you read them right after line 5. You could use this script http://www.webtoolkit.info/javascript-base64.html and call it like so:
      Code:
      formElement.value = Base64.encode(formElement.value); // in the onsubmit event of the previous page
      a = Base64.decode(a); // in the [I]callinput()[/I] function you just pasted
      Also, don't forget to decode the fields on the server side if you're processing them somehow, I'm not aware of any server-side scripting language that doesn't implement some way to decode base64-encoded values.
      BRILLIANT!! Thank you so much!

      Comment

      Working...