Jump to content

pass a username javascript variable to next page as hidden


Recommended Posts

<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

 

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.

 

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;

 

 

 

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.

 

<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?

 

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.

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.