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 15 of 15
  1. #1
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Transfer of variables to php page

    I am trying to transfer the variables of the form (username & password )in the html page to the process.php page which are both given below. However I am not able to read those values from the process.php page. Can anyone please let me know what is going wrong here? Thanks in advance and appreciate your help.

    HTML Page

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script language="JavaScript" type="text/javascript">
    function xor_str()
    {
    var username_val = document.forms['the_form'].elements["username"].value;
    var password_val = document.forms['the_form'].elements["password"].value;
    var xor_key='1234';
    var username_res="";
    var password_res=""
    for(i=0;i<username_val.length;++i)
    {
    username_res+=String.fromCharCode(xor_key^username_val.charCodeAt(i));
    }
    for(i=0;i<password_val.length;++i)
    {
    password_res+=String.fromCharCode(xor_key^password_val.charCodeAt(i));
    }
    // XOR is done

    //shifting the username_res to the left by 1 bit
    //username_res = username_res << 1;
    //shifting the password_res to the left by 1 bit
    //password_res = password_res << 1;

    //setting the xor'ed and shifted value for submission
    document.forms['the_form'].elements["username"].value = username_res;
    document.forms['the_form'].elements["password"].value = password_res;
    //alert("UserName: " + username_res);
    //alert("Password: "+ password_res);
    the_form.submit(); // is this step right?


    }
    </script>
    </head>

    <body>
    <form name="the_form" action="process.php" method="post">
    <table>
    <tr><td colspan="3">Username:<input type="text" name="username"></td></tr>
    <tr><td>Password: <input type="text" name="password"></td><td colspan="2"><input type="button" onClick="xor_str()" value="Submit"></td></tr>
    </table>
    </form>
    </body>s

    </html>






    Process.php page


    <html><body>
    <?php
    $username = $_POST['username'];
    $password = $_POST['password'];

    echo "You ordered ". $username . " " . $password . ".<br />";
    echo "Thank you ";

    ?>
    </body></html>

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You were correctly referencing the form for the most part of the script then suddenly when submitting it, you access it directly by name?! That will not work in non-IE browsers.

    Code:
    the_form.submit();
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks glenn for the reply. I tried using the syntax you suggested but still doesn't work. I am trying this in Mozilla Firefox, does that matter? I need to get this done ASAP. Please help me. THanks..

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    What syntax did you try? Did you debug and check for the new values of the username and password fields? Are you sure the new values are getting set? Did you also check for any errors in the console?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The one that you mentioned the_form.submit();

    I am using the basic editor Editplus.

    Regarding the username and password fields, those fields are getting updated with the encrypted values. The only problem I have is with transferring the variables to the php page. The page is not being redirected to the php page...

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I was not suggesting the code I posted was the one you need to use (you were already using it, right?), I was pointing out that this code was wrong. I said that you were referencing the form correctly (i.e. document.forms['the_form'].elements["username"].value) for the most part of the script but then when you submitted the form, you were referencing it wrong (i.e. the_form.submit())
    Last edited by glenngv; 11-18-2010 at 07:52 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried documents.forms["the_form"].submit(); this too but did not work. Thats when I tried that and posted.. Any help?

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Does it go to process.php and just display a blank page?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #9
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No its not going to that php page. Thats the problem

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Then there must be a js error. Did you check the js console to look for the error?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #11
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I copied and pasted your code and changed the_form.submit() with documents.forms["the_form"].submit() and it worked for me in Firefox. The form was submitted successfully and the browser tried to load process.php.


    Edit:
    (Ooppss..I just noticed this is my 10,000th post which makes me a Supreme Master coder! Yay! )
    Last edited by glenngv; 11-18-2010 at 08:27 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #12
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow thats terrific.. That calls for a party...


    I am using a basic editor so no option of checking at console..

    So it works for you ha? Does the php page load?

  • #13
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I thought you were using Firefox?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #14
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sure I am but its not working for me

  • #15
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Why can't you check the error console? Or better, check Firebug.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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