2

I am trying to get the value of WFFM form fields in code on submit button click. I tried Request.Form["First Name"]. but I am getting null for all field names even if the field has data. Can anyone please suggest how I can get field (text or checkbox) value. I am using the code below:

var nameField = this.Form.Fields.FirstOrDefault(m => m.Name == "First Name");
if(nameField != null && Request.Form["First Name"] != null)
{
    //Do something
}

2 Answers 2

1

You're using WFFM custom save action, so your Execute method should look like:

public void Execute(ID formid, AdaptedResultList fields, params object[] data)

What you can do to get the value of a field is to use the fields AdaptedResultList and create a helper method like:

private string GetValue(string formFieldId, AdaptedResultList fields)
{
    if (string.IsNullOrWhiteSpace(formFieldId))
    {
        return null;
    }
    if (fields == null || fields.GetEntryByID(formFieldId) == null)
    {
        return null;
    }
    return fields.GetValueByFieldID(formFieldId);
}

and then you call it as:

var FirstName = GetValue("First Name", fields);
0

Try getting the value from the FormSubmitContext object vs this. :

var postedFormData = formSubmitContext.PostedFormData;
var nameField = postedFormData.Fields.FirstOrDefault(p => p.Name.Equals("First Name");
if(nameField != null)
{
 ...
}

And check this out: https://ggullentops.blogspot.com/2017/10/sitecore-9-forms-custom-submit-action.html

Let me know if that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.