sungpeng Posted November 21, 2011 Share Posted November 21, 2011 <form action='test.php' method='post'> <input id="Username" type="hidden" name="date2" /> <input type="submit" name="action" value="Submit"></form> Hi I want to pass a Username javascript variable to test.php as hidden, anyone can help? When code this <input id="Username" type="input" name="date2" /> Data can pass to test.php When code this <input id="Username" type="hidden" name="date2" /> Data fail to pass over Quote Link to comment https://forums.phpfreaks.com/topic/251541-pass-a-username-javascript-variable-to-next-page-as-hidden/ Share on other sites More sharing options...
freelance84 Posted November 21, 2011 Share Posted November 21, 2011 a Username javascript variable Do you mean a javascript variable which you have names Username? Either write a hidden field to you page with js so is submitted on form submission or/ use ajax Quote Link to comment https://forums.phpfreaks.com/topic/251541-pass-a-username-javascript-variable-to-next-page-as-hidden/#findComment-1289956 Share on other sites More sharing options...
sungpeng Posted November 21, 2011 Author Share Posted November 21, 2011 yes it is inside Username and must be called out by "id=username" Quote Link to comment https://forums.phpfreaks.com/topic/251541-pass-a-username-javascript-variable-to-next-page-as-hidden/#findComment-1289960 Share on other sites More sharing options...
Adam Posted November 21, 2011 Share Posted November 21, 2011 The data sent in a POST method form *is* hidden from sight. It's not difficult to retrieve of course, but then again no client-side data is. If your system is vulnerable when somebody changes the value, then you need to rethink your server side security, not the client-side. Quote Link to comment https://forums.phpfreaks.com/topic/251541-pass-a-username-javascript-variable-to-next-page-as-hidden/#findComment-1289980 Share on other sites More sharing options...
Adam Posted November 21, 2011 Share Posted November 21, 2011 Whoops, misread your post. When code this <input id="Username" type="hidden" name="date2" /> Data fail to pass over You're not actually passing any data across..? Quote Link to comment https://forums.phpfreaks.com/topic/251541-pass-a-username-javascript-variable-to-next-page-as-hidden/#findComment-1289981 Share on other sites More sharing options...
freelance84 Posted November 21, 2011 Share Posted November 21, 2011 This really doesn't sound like a php question. Are you saying the variable is being created by some js function on the page after the client has loaded said html page, after which you wish to place said variable into "<input id="Username" type="hidden" name="date2" />" ? document.getElementById('Username').value= Username; Quote Link to comment https://forums.phpfreaks.com/topic/251541-pass-a-username-javascript-variable-to-next-page-as-hidden/#findComment-1289990 Share on other sites More sharing options...
sungpeng Posted November 21, 2011 Author Share Posted November 21, 2011 I am senting variable from Javascript to php but the data is stored in id=userName javascript variable. Is there other ways to extract as hidden so user cannot amend? Quote Link to comment https://forums.phpfreaks.com/topic/251541-pass-a-username-javascript-variable-to-next-page-as-hidden/#findComment-1290000 Share on other sites More sharing options...
freelance84 Posted November 21, 2011 Share Posted November 21, 2011 Sorry mate, really not sure i know what your trying to get at... From the OP: <input id="Username" type="hidden" name="date2" /> The hidden form element above is being assigned a value from a JavaScript variable which your server is receiving when the user submits the form. You are now asking for another way to submit the data from the client to the server which is safe from tampering... Without seeing your whole process start to end this is a pretty hard question to answer, however if you can see no other way of your server receiving the data (ie the only way is from the client) then i would guess your answer is no. Quote Link to comment https://forums.phpfreaks.com/topic/251541-pass-a-username-javascript-variable-to-next-page-as-hidden/#findComment-1290018 Share on other sites More sharing options...
sungpeng Posted November 21, 2011 Author Share Posted November 21, 2011 <html> <head> <title>Client Flow Example</title> </head> <body> <script> function displayUser(user) { var Username = document.getElementById('Username'); var greetingText = document.createTextNode('Greetings, ' + user.name + '.'); Username.appendChild(greetingText); } var appID = "YOUR_APP_ID"; if (window.location.hash.length == 0) { var path = 'https://www.facebook.com/dialog/oauth?'; var queryParams = ['client_id=' + appID, 'redirect_uri=' + window.location, 'response_type=token']; var query = queryParams.join('&'); var url = path + query; window.open(url); } else { var accessToken = window.location.hash.substring(1); var path = "https://graph.facebook.com/me?"; var queryParams = [accessToken, 'callback=displayUser']; var query = queryParams.join('&'); var url = path + query; // use jsonp to call the graph var script = document.createElement('script'); script.src = url; document.body.appendChild(script); } </script> The above code is like this. I am trying to get the username and put it in php then to mysql. If possible can extract the email from facebook as well? Quote Link to comment https://forums.phpfreaks.com/topic/251541-pass-a-username-javascript-variable-to-next-page-as-hidden/#findComment-1290069 Share on other sites More sharing options...
freelance84 Posted November 21, 2011 Share Posted November 21, 2011 If you want to send the js variable 'Username' to php without submitting your form (which it sounds like you do) then you need to use AJAX. Try searching the basics of AJAX if you don't know about AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/251541-pass-a-username-javascript-variable-to-next-page-as-hidden/#findComment-1290090 Share on other sites More sharing options...
sungpeng Posted November 21, 2011 Author Share Posted November 21, 2011 Use ajax or submit form. I want the username to be hidden and unable to edit when i insert into mysql using php. Quote Link to comment https://forums.phpfreaks.com/topic/251541-pass-a-username-javascript-variable-to-next-page-as-hidden/#findComment-1290106 Share on other sites More sharing options...
freelance84 Posted November 21, 2011 Share Posted November 21, 2011 I'm not going to write it for you mate... have a bash your self and post a specific problem if you hit one. Otherwise post it as a job in the freelance section. Or, if you have already hit a specific problem then be more specific in your question. Quote Link to comment https://forums.phpfreaks.com/topic/251541-pass-a-username-javascript-variable-to-next-page-as-hidden/#findComment-1290111 Share on other sites More sharing options...
sungpeng Posted November 21, 2011 Author Share Posted November 21, 2011 Understand.. Quote Link to comment https://forums.phpfreaks.com/topic/251541-pass-a-username-javascript-variable-to-next-page-as-hidden/#findComment-1290115 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.