In previous post i have shown you how to get the social data using social connected.
Now we will see how to auto populate these data to a web form for marketers Form Fields.
Prerequisite:-
Now we will see how to auto populate these data to a web form for marketers Form Fields.
Prerequisite:-
- Sitecore 8+
- Web form for marketers module
- Social connected configured.
We will be fetching LinkedIn data to a WFFM form using LinkedIn Login.
Step1- Setting up WFFM form in page.
For adding a form in page create a form item in sitecore.
Step2- Assign WFFM form to page and add LinkedIn login control
Step 3 - Configuring Form fields
To set default value to a form field we can set Rules.
By default sitecore provides few default action.
For populating social data we need to create a new rule.
Now we have to pass two parameters from Sitecore-"Name" and "Network" from Sitecore.
Custom rule will look for the "ln-headline" property in context user's Linkedin social profile. If any value is found it will return the value else it will return blank.
Below is the Output
- Hide element
- Use value from query string
- Use value from profiles specific field
- Use value from specific visitor tag
For populating social data we need to create a new rule.
Step 4- Creating new WFFM action rule.
- Navigate to "/sitecore/system/Settings/Rules/Definitions/Elements/Web Forms for Marketers Actions"
- Right click and insert new Action.
- Provide your custom method and reference details. As below.
Method- SCcustom.ReadPropertyFromMongo
using Sitecore.Security.Accounts;
using System;
using System.Collections.Generic;
using Sitecore.Diagnostics;
using Sitecore;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using Sitecore.Social.Api;
namespace SCcustom
{
public class ReadPropertyFromMongo<T> :
Sitecore.Forms.Core.Rules.ReadValue<T> where T : Sitecore.Forms.Core.Rules.ConditionalRuleContext
{
private string Network { get; set; }
protected override object GetValue()
{
try
{
string networkname = "LinkedIn";
networkname = Network;
//
Sitecore.Context.User.Profile.GetCustomProperty("soc_PrimaryNetwork")
;
var socialProfile = new SocialProfileManager();
// Do we have an extra profile from the
user?
if (socialProfile.SocialProfileExists(Sitecore.Context.User.Name,
networkname))
{
var soProfile =
socialProfile.GetSocialProfile(Sitecore.Context.User.Name, networkname);
try
{
return
soProfile.Fields[Name];
}
catch
{ return ""; }
}
return "";
}
catch
{ return "network error"; }
}
}
}
Now we have to pass two parameters from Sitecore-"Name" and "Network" from Sitecore.
Custom rule will look for the "ln-headline" property in context user's Linkedin social profile. If any value is found it will return the value else it will return blank.
Below is the Output