I'm not sure how to ask my question, but I have a contact form that is include on every page of my website: http://assistedlivingbridgeton.com/ (the "schedule your tour" form).
Currently, this is the form processing code:
<?php
// if the url field is empty
if(isset($_POST['url']) && $_POST['url'] == ''){
// then send the form to your email
$email = "knunn#standrews1.com, eechols#standrews1.com";
$message = "The following information was submitted from the Schedule Your Tour form on your website:\n
";
$message .= "Name: ".$_REQUEST["Name__1"]."\n\n";
$message .= "Email: ".$_REQUEST["Email__2"]."\n\n";
$message .= "Phone: ".$_REQUEST["Phone__3"]."\n\n";
$message .= "Best date/time: ".$_REQUEST["Best_datetime__4"]."\n\n";
mail( $email, "Bridgeton Assisted Living Tour Form", $message, "From: $email
X-Priority: 1 (Highest)" );
header("Location: http://www.assistedlivingbridgeton.com/thanks.php");
}
// otherwise, let the spammer think that they got their message through
?>
<h1>Thanks</h1>
We'll get back to you as soon as possible
?>
What I would like to do is have one form processing script that pops in a "thank you" message kinda like a php include where that Tour Form is on the sidebar. The way I have it set up now, I have to have a process script and a thankyou page for each landing page on my site that has that form. I want one script, that will pop in the thank you message to whatever page the form was filled out from. Does that make sense? Help please! I know its possible because if you use Foxy Form or something similar, that's exactly what it does.
You can use <iframe> to do that.
You create a file : form.php, write all your code including the thank you and the form itself and then just call this page where ever you want using iframe. Thus you add this code to all pages where you want the form to appear and the result thank you will appear in the same page:
<iframe src="form.php" width="150px" height="250px" border="0">
more information about iframe you can get here: w3schools iframe
Related
I have a web-based news app that runs on Heroku. When users post a comment to a news story on my app, my app forwards the comment to the user's facebook wall using fb_graph. Everything worked perfectly until a couple of weeks ago. For no reason that I can explain I am now seeing some baffling behavior.
Now, when a user submits a comment to a story the FB API responds with, OAuthException :: (#1500) The url you supplied is invalid. If, the same user then submits additional comments to the same story those comments are posted to the user's FB feed just fine.
I have used the FB Graph API explorer to confirm that I have valid access tokens, and that my app does accept posts to the token-owner's FB feed.
To make things even more baffling, when running my web app in development on localhost all of the posts go through just fine to my development FB app.
def post_to_facebook(story, post)
auth = Authentication.find_by_provider_and_user_id("facebook", current_user.id)
if auth
me = FbGraph::User.me(auth.token)
if me.permissions.include?(:publish_stream)
begin
me.feed!(
:message => "#{best_name(current_user)} made the following post to NewsWick: #{post.contents}",
:name => story.title,
:link => "https://www.newswick.com/stories/"+story.id.to_s,
:description => "Story posted to the NewsWick world-wide news service" ,
:picture => best_photo(story)[:photo_url]
)
rescue => e
#msg = "Facebook posting error: "+ e.to_s
puts "Facebook feed posting error: #{e.message}"
end
else
#msg = "No longer authorized to post to Facebook."
end
end
return #msg
end
One last thing to note, the only thing that I have changed w/r/t how my app interacts with FB in the last two weeks was that i accepted FB's July Breaking Changes.
Anyone have any clues. This is driving me bonkers!!!
I'm having the same issue only difference is I'm using the javascript api.
Seems like it's a facebook bug, which is already reported here: https://developers.facebook.com/bugs/136768399829531
Yes this is a known bug and Facebook developers are looking into it, well so they claim,however something interesting I found out is:
I post to my Facebook using 2 methods using RestFB API , first, for messages with URLs e.g www.something.com and those without URLs, I realized last night that all posts without URL worked and the ones with URL doesn't.
So I changed all my implementation to send messages to Facebook without using with link parameters for all posts, with or without links.
With link Parameter - throws error #1500
FacebookType publishMessageResponse = resftFBclient.publish(FACEBOOK_PAGE_ID
+"/feed", FacebookType.class, Parameter.with("message", "Hello StackOverFlow!"),
Parameter.with("link", "message with a link , www.me.com"));
With no link parameter - this works even if message contained URL/link
FacebookType publishMessageResponse = resftFBclient.publish(FACEBOOK_PAGE_ID. +
"/feed",FacebookType.class,Parameter.with("message", "My message"));
This works even if message contained URL/link and it creates an clickable link on FB. Could it be that FB is trying to drop the link implementation and letting us figure it out that the former works just as the link implementation? What's the difference anyways?
That's brutal!
Cheers
Babajide
I was trying to solve this problem this problem that seems to be occurring to almost everyone.
I am using the PHP SDK.
What I noticed is that it always returned this error for the first time I tried to post the link. On a second try, it was posted with success.
Really hackishly I then checked for an error and retried to post to the wall.
$errorCount = 0;
function postPicture($phrase)
{
try
{
$image = $_SESSION['photoLink'];
$facebook->setFileUploadSupport(true);
$response = $facebook->api(
'/me/feed',
'post',
array(
'message' => $phrase,
'picture' => 'http://mylink/pictures/facebook.png',
'link' => $image,
'caption' => 'My caption',
'description' => 'My description',
'type' => 'photo',
'name' => 'My name'
)
);
echo 'Success';
}
}
catch (FacebookApiException $e)
{
// You really should check if this $error is #1500 before doing that. I didn't :)
if($errorCount < 2)
{
postPicture($phrase);
$errorCount++;
}
else
{
$e = str_replace('"', "", $e);
$e = str_replace("'", "", $e);
echo 'Error ' . $e;
}
}
}
To solve these problems just make sure you add these og metadata tags in the head section of the page represented by the url you want to share:
<meta property="og:type" content="article" /> //or any other type like blog, website etc....
<meta property="og:url" content="your article url here" />
<meta property="og:title" content="your article title here" />
Good luck!
I created a like button on a page (http://www.usna.edu/BillAF/game.php) that sends the URL/data for it's parent page. Unfortunately, when I first put it in, an older version of the page was at the location of the parent page that did not have the open graph meta-tags on it.
So when someone "likes" the page, it sends the wrong title and a "garbage" image of half of the letter "e" on a white and gray square.
I checked: http://developers.facebook.com/tools/debug and it has the updated info. I also tried changing the associated AP ID to a new one, and neither seems to have refreshed what it sends when I "like" it. I also tried adding index.php to the end of the URL it is supposed to be posting (http://www.usna.edu/BillAF) but to no avail.
Is there anything I can do to force it to re-scrape the page? If not, does anyone know how long it will take for facebook to re-scrape it on their own?
A good way to clear the facebook cached image and text is by running the tool Debugger:
http://developers.facebook.com/tools/debug
By putting the url that you are sharing there, it will refresh facebook cache from your website.
Facebook has an API for re-scraping page data, I use the following function:
function purgeFacebookCache($url, $debug=false) {
// Set the variables for Facebook
$fields = array(
'id' => urlencode($url),
'scrape' => true
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
// Connect
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://graph.facebook.com');
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result = curl_exec($ch);
// Debug
if ($debug) {
var_dump($result);
}
}
I'm trying to create a page in Wordpress that will display the user's Facebook ID after they have logged in to our Wordpress site using WP-FB AutoConn plugin (to sign in using their Facebook credentials).
For the Facebook game the site is being built to offer community support for, the user needs to know their facebook ID (which they frequently don't know how to find, which then has to be explained to them).
Since they are logging into the Wordpress site with their Facebook credentials, it seems like we should be able to have a page they can go to that would display their Facebook ID.
I used:
<?php global $current_user;
get_currentuserinfo();
echo 'Username (user_login): ' . $current_user->user_login . "\n";
echo 'User email (user_email): ' . $current_user->user_email . "\n";
echo 'User first name (user_firstname): ' . $current_user->user_firstname . "\n";
echo 'User last name (user_lastname): ' . $current_user->user_lastname . "\n";
echo 'User display name (display_name): ' . $current_user->display_name . "\n";
echo 'User ID (ID): ' . $current_user->ID . "\n";
?>
...which displays the Wordpress login info.
Initially I thought the user_email was their facebook ID preceded by FB_ (as in: FB_665611340#unknown.com --which is how it shows up under "Users" in Wordpress), but that must be a randomly generated number because it isn't their facebook ID.
I'm not really a coder, but trying to learn, any insight appreciated!
What I had WAS correct (WP-FB AutoConn uses the facevook ID in the email account it stores in Wordpress).
I spent a week researching, testing, taking code snippets that didn't apply and trying to make them work (BEFORE I came here and asked), so, I was disappointed to see that the question itself got a negative mark.
But now I have the answer.
FOR PEOPLE WANTING TO LEARN, HERE'S THE SOLUTION:
The variable "$email4" can be whatever you like.
Also, I decided to take the result of stripping away the extraneous stuff (from the email address) and putting the result in a variable called "$emailStripped" so I could concatenate it cleanly just using the variable name.
<?php $email4 = $current_user->user_email;
$emailStripped = substr($email4, strpos($email4,"<")+3, strrpos($email4, "#")-strpos($email4,"<")-3);
echo 'If you logged in using your Facebook account, your Facebook ID should be:' . "\n" . $emailStripped . "\n";
?>
To use this in Wordpress you will need either a plugin that allows PHP, or to create a template file with the PHP in it, create your page then select that template for it.
I know there are many Q&A on here about this but I can't seem to make sense of them because they don't show full code examples or are for doing something different than what I'm trying to do.
I have a simple facebook welcome-test tab. Not a canvas app. I want to be able to get the users id but have to make it prompt them for access to that info before it will show up in the signed request.
So what I'm looking for is a code example for a simple welcome tab. I don't need a login page or anything like that since this will be in the fan content page so they will have to be logged in already. I just want that dialog box to popup asking them for permission so I can get the userid.
Thanks
Edit:
I wanted to add that I just figured out my problem but it's not really an answer to this question. I figured out how to get the user id without asking the user for permission to access their profile. It was as easy as adding this code to the page and it works in a tab and canvas app the same way. getUser() by its self returns 0 but since the user is already logged in to be seeing this content, when getUser() returns 0, then the code simply gets the user id from the API method. Now that I finally figured this out it seems simple.
$session = $facebook->getUser();
if (!$session) {
$url = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0
));
echo "<script type='text/javascript'>top.location.href = '$url';</script>";
} else {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$updated = date("l, F j, Y", strtotime($me['updated_time']));
echo "Hello " . $me['name'] . "<br />";
echo "You last updated your profile on " . $updated;
} catch (FacebookApiException $e) {
echo "Error:" . print_r($e, true);
}
}
I'd still like to know if there is a way to make the extended permissions dialog show for a tab app so it will be good to see solutions for php sdk.
you need to prompt them for allowing your application to pull data on the user
this can be done using the JS SDK's function FB.login(). you can have more details in the facebook documentation : http://developers.facebook.com/docs/reference/javascript/FB.login/
notice that the popup can be opened only on mouseclick or keyup events - otherwise popup blockers will block it.
you will also have to set a domain and site url to the application in the developers site, and init the facebook js library (the loading paragraph in - http://developers.facebook.com/docs/reference/javascript/)
<div onclick="login();">click here to login</div>
<script type="text/javascript">
function afterLogin(){
alert("user logged");
}
function login(){
FB.getLoginStatus(function(response){
if(response.status=="connected")
{
afterLogin();
} else {
FB.login(function(response){
if(response.status=="connected")
{
afterLogin();
}
});
}
});
}
</script>
I don't think facebook allows this... Facebook does not want a user's tab to be able to detect who is looking at it, and possibly displaying information to a user's friends that isn't displayed to the user.
I can be wrong :)
This code is almost perfect for what I need:
<form onsubmit="location.href='http://www.mysite.com/' + document.getElementById('myInput').value; return false;">
<input type="text" id="myInput" />
<input type="submit" />
</form>
The only thing missing is if they user puts in an input that does not exist I want it to take them nowhere or redirect back to the same page. Right now it takes them to an error page and they have to use the back button to go back and try again.
Any help will be greatly appreciated.
Thank you
Could you perhaps write a small PHP script that you use as the form action? Inside this script, you could check the supplied user input and validate that the URL exists. If it does, you could do a header() redirect to the given page. If it does not exist, you could redirect them to the desired page.
<?php
$input = $_POST['myInput']; // You'll also need to add in a name='' tag in the HTML!
$desired_page = ''; // page you want to go to if inputted file cannot be found
if (file_exists($input)) {
header("Location: $input");
}
else {
header("Location: $desired_page");
}
It'd need a lot of refining, but that's the idea. Would that do what you want?