Client-side validation with Facebook Registration XFBML - facebook

I'm using XFBML embedded in a HTML5 document. I've set up client-side validation following the instructions provided in the "Registration Advanced Uses" doc on Facebook's site, but it only shows errors on blur, and doesn't validate when I click the "Register" button (so if I fill out a field wrong and click outside on another element, it displays the error, but then I can click on the Register button and it registers me anyway).
I've traced it in the JS debugger, and by adding alert/log statements, and my validate_registration function only gets called onblur, and never when I click the Register button.
Anyone seen this behavior and know what I'm missing here? The live example Facebook has on the "Registration Advanced Uses" works perfectly, so I know I've got a mistake somewhere.
My XFBML tag is this:
<div class="fb-registration"
onvalidate="validate_registration"
fields="[
{'name': 'name'},
{'name': 'first_name'},
{'name': 'gender'},
{'name': 'email'},
{'name': 'user_type', 'description': 'Are you a?', 'type': 'select',
'options': {
'parent': 'Parent/Guardian looking for childcare',
'sitter': 'Babysitter/Nanny looking for sitting jobs'
}
},
{'name': 'zip_code', 'description': 'Zip code', 'type': 'text'},
{'name': 'over_eighteen', 'description': 'I am at least 18 years old', 'type': 'checkbox' }
]"
fb_only="true"
redirect-uri="<%= parse_fb_connect_signed_request_users_url %>"
width="530">
</div>
and my validation function is this:
function validate_registration (custom_fields) {
var errors = {},
regexZipCode = /^\d\d\d\d\d$/;
console.log("in validate_registration");
if (custom_fields.user_type !== 'parent' && custom_fields.user_type !== 'sitter') {
errors.user_type = "Select either Parent or Sitter";
}
if ( ! regexZipCode.test(custom_fields.zip_code) ) {
errors.zip_code = 'Enter your 5-digit U.S. zip code';
}
if ( ! custom_fields.over_eighteen ) {
errors.over_eighteen = 'You must be at least 18 years old to use this site!';
}
return errors;
}

So, never mind this.
I was getting the message "You've just registered for X using your Facebook account.
If you didn't mean to do this, you can undo this below." and thought that it meant I had registered. But if I click "Continue" at that point, it shows me all the validation errors, so it does work correctly - it just doesn't validate until after the final step.

Related

Facebook sharing: going from 'feed' to 'share_open_graph'

I'm messing around with an Angular app, let's say for the sake of argument that I'm not using any meta tags, how can I use the Share Dialog to let users share pages of my app?
Using the old Feed Dialog works, but it has been deprecated:
$scope.share = function() {
FB.ui({
method: 'feed',
name: 'This is the name field',
link: 'The link',
picture: 'The picture',
caption: 'The caption',
description: 'This is the content of the "description" field, below the caption.'
})
},
function(response) {
if (response && !response.error_code) {
console.log('Posting completed.');
} else {
console.log('Error while posting.');
}
});
};
So even though this works, I want to use the Share Diolog in the same way but I'm not figuring it out. This is sort of what I've been trying, keep in mind that I'm a newbie:
$scope.share = function() {
FB.ui({
method: 'share_open_graph',
action_type: 'og.likes',
action_properties: JSON.stringify({
object: {
'title': 'The title',
'image': 'An image',
'url': $scope.shareUrl,
'description': 'This is the description',
}
})
},
function(response) {
if (response && !response.error_code) {
console.log('Posting completed.');
} else {
console.log('Error while posting.');
}
});
};
Any hints?
The short answer is that you can't, you must use OpenGraph meta tags.
Since Facebook doesn't understand JavaScript and thus Angular, you must detect Facebook's crawlers server-side and render a static page for them instead of the Angular app.
While the precise implementation will vary depending on your server technologies, here's the general idea:
Setup a route for the resources that need sharing: http://example.com/resources/:id
Look for the user-agent
If it's one of Facebook's crawlers, fetch the resource and render a simple view with OpenGraph tags and an empty body. Otherwise, simply render the Angular app.
Facebook's crawlers are available here and they currently are:
facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)
facebookexternalhit/1.1
Facebot

How to submit a form using JsonP in Sencha Touch 2?

I'm writing an application using Sencha Touch 2, it works just fine when accessed from web. The problem came when I built it for iPhone and changed the url from a local url (../services/myservice.php) to a remote url (http://remoteurl.com/services/myservice.php)
I started getting a crossdomain error:
**XMLHttpRequest cannot load http://example.com/services/userRegister.php?_dc=1336972603884. Origin http://localhost is not allowed by Access-Control-Allow-Origin.**
And I'd like to ask you if there is a way to submit a form using jsonp, so I don't have this problem anymore.
Here is my code for the form:
Ext.define('RegistroMovil.view.Register',{
extend: 'Ext.form.Panel',
xtype: 'register',
requires:[
'Ext.form.FieldSet',
'Ext.form.Email'
],
config: {
title: 'Register',
iconCls: 'user',
url: 'http://example.com/proys/congreso/services/userRegister.php',
items: [
...
And the code of the button that submits the form:
{
xtype: 'button',
text: 'Register',
handler: function(){
this.up('register').submit({
success: function(f, a){
alert('Your id: ' + a.id);
f.reset();
}
});
}
},
Thank you very much!
You are getting the above error because of cross-origin resource sharing policy.
On the tap event handler of submit button, you could use an Ext.Ajax.request(); but I feel that would also land up you getting the same error.
E.g
Ext.Ajax.request({
values : paramValues // values from form fields..
url: '.../test.php',
success: function(response) {
console.log(response.responseText);
}
failure: function(response) {
console.log(response.responseText);
}
});
So, it's better to write an Ext.util.JSONP.request() to handle a form submit.
Note that if you are retrieving data from a page that is in a domain
that is NOT the same as the originating domain of the running page,
you must use this class, because of the same origin policy.
E.g
Ext.util.JSONP.request({
params: paramValues // values from form fields..
url: '.../test.php',
callbackKey: 'callback',
scope: 'this',
success: function(response) {
console.log(response.responseText);
}
failure: function(response) {
console.log(response.responseText);
}
});

action links text in facebook post to wall dialog using javascript not working

I trying to bulid a facebook application using javascript.In my application, the user gets the result and a dialog after a time delay popup. Everthing is working well except one here's my code for the 'post to wall dialog'
<script>
var publish = {
method: 'stream.publish',
display: 'popup', // force popup mode
attachment: {
name: 'Connect',
caption: 'The Facebook Connect JavaScript SDK',
actions: [{ name: 'action_links text!', link: 'http://www.example.com' }],
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
href: 'http://www.example.com/'
}
};
FB.ui(publish, Log.info.bind('stream.publish callback'));
</script>
The line containing actions not working for me.Can anyone just inform what is the solution for this...
The property should be called action_links not actions and only have text and href values. Use something like:
action_links: [{ text: 'action link test', href: 'http://example.com'}]
Note that the action must be defined through the fb web interface for the app!

Use of FB.ui with method permissions.request opens popup

I am working on a Facebook IFrame app and using FB.ui to display the permissions request dialog using the JS SDK.
Here is the code I`m using:
FB.ui(
{
method: 'stream.publish',
message: '',
attachment: {
name: 'תחרות התחפושות הגדולה של לגדול',
caption: '',
media: [{ 'type': 'image', 'src': 'http://www.p-art.co.il/ligdol_purim/logo.gif', 'href': 'http://apps.facebook.com/ligdolpurim/', 'width': '101', 'height': '84'}],
description: ('פורים 2011'),
href: 'http://apps.facebook.com/ligdolpurim/'
},
action_links: [
{ text: 'Ligdol Purim', href: 'http://apps.facebook.com/ligdolpurim/' }
],
user_prompt_message: 'פרסם את השתתפותך בתחרות'
},
function(response) {
alert(response.post_id);
});
}
A happy surprise is that the SDK knows to show the dialog only for the missing permissions (if any). The problem is that a new IE window pops up and then disappears before the dialog is shown inside an iframe.
I have tried several variations on this code I found all over the net and all of them give me this popup before showing the dialog.
I had not considered that in order to open a facebook lightbox, you actualy need to be on facebook. I was testing my IFrame outside facebook. When I began testing the app inside a page tab, I got the lightbox. Ya learn something new everyday.

Facebook JS API: How to get FB.Connect.streamPublish to use auto_publish

I'm trying to publish stuff to someone's wall.
It works, but I'm also trying to use the auto_publish feature so the user will only get one popup granting the publish_stream extended permission.
So I set streamPublish's auto_publish to true, but I still get the popup asking me if I want to publish and/or edit the message.
What am I doing wrong?
Here's what I'm running:
FB.ensureInit(function () {
FB.Facebook.get_sessionState().waitUntilReady(function() {
FB.Connect.showPermissionDialog("publish_stream", function(perms) {
if (perms == "publish_stream") {
FB.Facebook.apiClient.friends_get(null, function(result) {
var markup = "";
var targets = result;
targets = [testFriendsIDForTesting];
var attachment = {
name: "Blablabla",
href: window.location.href,
description: "description",
caption: "caption"
};
var actionLinks = [{
text: "View",
href: window.location.href
}];
var num_targets = targets.length;
for (var i=0; i<num_targets; i++) {
var fId = targets[i];
FB.Connect.streamPublish("none", attachment, actionLinks, fId, "none", null, true);
}
});
}
});
});
});
Came across this thread as im having the same issue, which i solved (without having to use the other apiClient call).
You are right in your answer above, in that FB are not setting the autoPublish settings properly.
The workaround is to make a call to FB.Connect.forceSessionRefresh before attempting to publish.
My code before:
function fbPublish() {{
FB.ensureInit(function() {{
FB.Connect.streamPublish('{0}', {1}, {2}, null, 'Anything else you would like to add?', fbPublishCallback, true, null);
}});
}}
Code now:
function fbPublish() {{
FB.ensureInit(function() {{
FB.Connect.forceSessionRefresh(function() {{
FB.Connect.streamPublish('{0}', {1}, {2}, null, 'Anything else you would like to add?', fbPublishCallback, true, null);
}});
}});
}}
The only reason im using this "old" JavaScript method is because there is a current bug with the Graph API where you cannot post action links.
I have no idea what kind of developers they have over at Facebook, because the issues i have run into have been disgraceful (this, Graph API not allowing action links, '' instead of null causing "Application Server Error", etc).
Hope this helps someone else out.
The problem stems from the last parameter your passing as false. This is the auto_publish bool, so even with the permissions granted with this set to false it will prompt the user if they want to publish it or not.
// Set auto publish to true
FB.Connect.streamPublish("none", attachment, actionLinks, fId, "none", null, true);
I'm still unsure why this doesn't work as expected, but I've checked the FB JS code and it's failing to set my user autoPublish settings properly in it's userInfo object.
So I've worked around this by calling stream.publish via:
FB.Facebook.apiClient.callMethod("stream.publish", c, new FB.ImmediateSequencer(function(n,m){