How to retrieve a value from a form in PHP and use it in Fb.ui Publish to wall Function

StackOverflow https://stackoverflow.com/questions/8726470

  •  14-04-2021
  •  | 
  •  

Question

I would like to make a facebook page tab with a form field, where visitors can fill in a value and then press a post to wall button where this value will be used in the name value of the fb.ui publish to wall function.

Can someone point me to the right direction?

This is what I use to post to wall.

<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
  FB.init({appId: <APPID>,
              status: true,
              cookie: true,  
              xfbml: true});  };  
     (function() {
         var e = document.createElement('script');
         e.async = true;  
         e.src = document.location.protocol +  
         '//connect.facebook.net/en_US/all.js';
         document.getElementById('fb-root').appendChild(e);
     }());
 </script>

<script>
function publish_to_wall(){
   FB.ui({ 
     method: 'stream.publish',
     display: 'iframe',
     name: '<VALUE TO RETRIEVE FROM FORMFIELD> blablablalba',
     caption: '<TEXT>',
     link: 'http://www.facebook.com/<MYPAGE>',
     picture:'<IMAGE URL>'
   });
 }
</script>

To have a view on the tab you can check here: http://www.socialogika.com/tabs/hp/index.html

For now the formfield is still an image, and the share button is not active yet... But it gives you a better view what I mean to realise...

The Button should directly initiate the popup dialog.

Was it helpful?

Solution

give the form an id... then use document.getElementById("theID").value , not really a facebook question though...

cheers

Extended example:

<input type='text' id='myText' />


<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
  FB.init({appId: <APPID>,
              status: true,
              cookie: true,  
              xfbml: true});  };  
     (function() {
         var e = document.createElement('script');
         e.async = true;  
         e.src = document.location.protocol +  
         '//connect.facebook.net/en_US/all.js';
         document.getElementById('fb-root').appendChild(e);
     }());
 </script>

<script>
function publish_to_wall(){
   FB.ui({ 
     method: 'stream.publish',
     display: 'iframe',
     name: document.getElementById('myText').value,
     caption: '<TEXT>',
     link: 'http://www.facebook.com/<MYPAGE>',
     picture:'<IMAGE URL>'
   });
 }
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top