Skip to content

Instantly share code, notes, and snippets.

View PetersonDave's full-sized avatar

David Peterson PetersonDave

View GitHub Profile
@PetersonDave
PetersonDave / gist:6921396
Last active December 25, 2015 04:59
Sitecore web forms pipeline override
<successAction>
<processor type="Sitecore.Form.Core.Pipelines.SuccessRedirect, Sitecore.Forms.Core"/>
<processor type="Custom.Pipelines.FormatSuccessMessage, Custom"/>
</successAction>
@PetersonDave
PetersonDave / gist:6921298
Created October 10, 2013 16:28
Google Analytics Event Save Action. As the form action is empty, we're using this to tag a form as one which should track form submits in Google Analytics.
public class RecordGoogleAnalyticsSubmitAction : ISaveAction, ISubmit
{
public void Execute(ID formid, AdaptedResultList fields, params object[] data)
{
return;
}
public void Submit(ID formid, AdaptedResultList fields)
{
return;
@PetersonDave
PetersonDave / gist:6911816
Created October 10, 2013 01:50
Web.config - pickup directory
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\temp\maildrop\"/>
</smtp>
</mailSettings>
</system.net>
@PetersonDave
PetersonDave / gist:6895451
Last active December 25, 2015 01:29
Example of how to access a field on a WFFM form outside the validator's field context.
protected override bool OnServerValidate(string value)
{
// get the form
var form = WebUtil.GetParent<SimpleForm>(this);
// find another field within our form
var field = (SingleLineText)WebUtil.FindFirstOrDefault(form, c => c is SingleLineText && (c as SingleLineText).Result.FieldName == "City");
// compare values between this field (State) and the value of a different field (City)
bool isBoston = field != null && field.Result.Value.ToString() == "Boston";
@PetersonDave
PetersonDave / gist:6805162
Last active December 24, 2015 13:29
Form field validation for complex fields. Parse query in field's parameters field value. Query then executed for query results, representing data source of a drop down list field.
private static bool IsValueInFieldDatasource(IEnumerable<ControlResult> fields, string fieldName, string value)
{
Sitecore.Diagnostics.Assert.IsNotNullOrEmpty(fieldName, "fieldName cannot be null");
if (string.IsNullOrEmpty(value)) return false;
bool isValidSelection = false;
var field = fields.FirstOrDefault(x => string.Compare(x.FieldName, fieldName, StringComparison.OrdinalIgnoreCase) == 0);
if (field != null)
{
@PetersonDave
PetersonDave / gist:6805061
Last active December 24, 2015 13:29
Check User Password complex validation
namespace Sitecore.Form.Submit
{
public class CheckUserPassword : CheckUserAction
{
...
public override void Execute(ID formid, IEnumerable<ControlResult> fields)
{
string empty;
string failedMessage = base.FailedMessage;
string str = failedMessage;
@PetersonDave
PetersonDave / gist:6804928
Created October 3, 2013 04:20
Sitecore Password-Confirmation validator
using Sitecore.Form.Core.Validators;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Sitecore.Form.Core.Client.Validators
{
public class PasswordConfimationValidator : FormCustomValidator
{
protected override bool OnServerValidate(string value)
{
@PetersonDave
PetersonDave / gist:6800139
Created October 2, 2013 20:36
Prevent users from submitting forms twice in Sitecore's Web Forms for Marketers.
using System;
using Sitecore.Form.Core.Renderings;
using Sitecore.Form.Web.UI.Controls;
namespace Custom.Form.Web.UI.Controls
{
public class PreventDoubleClickFormRender : FormRender
{
// disables submit button if group validator for submit is valid
private const string PreventDoubleSubmitJs = @"function disableSubmitButton(groupValidator, submitButton) {{ $(submitButton).disabled = Page_ClientValidate(groupValidator);}}";
// maintaining format of original source.
public override bool SetValidatorProperties(BaseValidator validator)
{
base.SetValidatorProperties(validator);
object obj = null;
if (validator as ICloneable != null)
{
obj = ((ICloneable)validator).Clone();
}
@PetersonDave
PetersonDave / gist:6441921
Last active December 22, 2015 07:59
Move a rendering
// Move renderings example usage
var rendering = device.Renderings.Cast<RenderingDefinition>().SingleOrDefault(r => r.ItemID == MyRenderingId);
device.MoveRenderingUp(rendering);
item[Sitecore.FieldIDs.LayoutField] = layoutDefinition.ToXml();
// DeviceDefinition Extensions
public static class DeviceDefinitionExtensions
{
public static void MoveRenderingDown(this DeviceDefinition deviceDefinition, RenderingDefinition renderingDefinition)
{