#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Santa Barbara, CA, USA
    Posts
    11
    Rep Power
    0

    url encode w/javascript for redirect


    I'm integrating a service with iBill, a merchant account service, and running into a problem on Netscape Navigator. I'm loosing variables because the url is not being incoded.

    Here's the scenario. When the end user fills out their info at iBill and the transaction is good, iBill forwards them to a web good page that I've created and posted on their servers. My web good page is a redirect to a PHP page on my server which takes the variables passed in the url and dumps them into a database.

    I need to url encode the redirect string on the web good page but their servers are not running PHP so I need do it in Javascript...which I'm no good at.

    I did find some code at http://www.blooberry.com/indexdot/ht...rlencoding.htm but that's directed to a form. I need to customize or rewrite the javascript so it url encodes the string, everytime not onSubmit.

    Any help would be appreciated. This job is sooooo close to being done!
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    escape is the function you are looking for. Do not escape the whole url. Only escape the VALUE of your variable. example:
    PHP Code:
    var page "http://www.clanmisfire.com/index.php"
    var variable "?variable_name=";
    var 
    value escape("variable_value");

    location page+variable+value;

    OR

    document.write(page,variable,value); 
    Just two of many ways it could be done. Hope that helps.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Santa Barbara, CA, USA
    Posts
    11
    Rep Power
    0
    If I had to build a long string could I do it like so;

    var*page*=*"http://www.clanmisfire.com/index.php"
    var*url_string*=*"?name=";
    var*url_string*.=*escape("%%CUSTNAME?");
    var*url_string*.=*"?address=";
    var*url_string*.=*escape("%%CUSTADDR1?");

    %%CUSTNAME? is how I call variables on iBill's server.
  6. #4
  7. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    You sure could. I was going to put an example like this:
    PHP Code:
    var page = "http://www.clanmisfire.com/index.php"
    var variable = "?variable_name=";
    var value = escape("<?= getValue()?>");

    location = page+variable+value;

    OR

    document.write(page,variable,value);
    But I didnt want to confuse you if you werent using php. It is the same concept. Repeat as neccessary. Only one thing - when using MORE than one name/value pair, you must offset the subsequent name/value paris using the Ampersand (&). Like so:
    PHP Code:
    var page "http://www.clanmisfire.com/index.php" 
    var url_string "?name="
    var 
    url_string .= escape("%%CUSTNAME?"); 
    var 
    url_string .= "&address=";             // <-- notice the ampersand
    var url_string .= escape("%%CUSTADDR1?"); 
    Just to reiterate, the query string is started with the question mark and uses the ampersand as the delimeter for the variables.
    Code:
    fully made URL:
    www .clanmisfire.com/index.php?prefered_figure=athletic&hair_color=brunette&income=loaded%20with%20money 
    /*space in url so page wont pick up as link */
    Hope that helps!
    Last edited by Nemi; August 23rd, 2001 at 08:10 PM.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Santa Barbara, CA, USA
    Posts
    11
    Rep Power
    0

    what worked


    Thought I would post the code that worked for me.

    Here's the scenario. We're using a service called iBill. I posted what's called a web good page, called when the transaction is good, on their server. I needed to pass variables from their server to my php page.

    Here's the code;

    <html>
    <head>
    <title>PHP collect page</title>
    <script language="JavaScript">
    <!--
    var page="http://www.myserver.com/relay.php";
    var url_string="?trans_id="+escape("%%TRAN?")+"&sub_acct="+escape("%%REF5?")+"&delay="+escape("%%REF4?") ;
    window.location=page+url_string;
    //-->
    </script>
    </head>

    Hope it helps someone.

    Tom

IMN logo majestic logo threadwatch logo seochat tools logo