bartverdonck / Sitecore-Forms-Extensions

http://onelittlespark.bartverdonck.be/category/sitecore-forms-extensions/
MIT License
59 stars 37 forks source link

Unknown method 'GetStringValue' #128

Open dbalosetti opened 2 years ago

dbalosetti commented 2 years ago

When we add the recaptcha module we get an exception when we try to submit the form:

5952 11:03:25 ERROR [Experience Forms]: Unknown method 'GetStringValue' (type: Feature.FormsExtensions.Fields.ReCaptcha.ReCaptchaModel) Exception: System.InvalidOperationException Message: Unknown method 'GetStringValue' (type: Feature.FormsExtensions.Fields.ReCaptcha.ReCaptchaModel) Source: Sitecore.Kernel at Sitecore.Reflection.ReflectionUtil.CallMethod(Object obj, String methodName, Boolean includeNonPublic, Boolean includeInherited) at Sitecore.ExperienceForms.Mvc.Processing.SubmitActions.SendEmail.GetFieldValue(IViewModel postedField) at Sitecore.ExperienceForms.Mvc.Processing.SubmitActions.SendEmail.ReplaceFieldValues(String content, FormSubmitContext formSubmitContext) at Sitecore.ExperienceForms.Mvc.Processing.SubmitActions.SendEmail.SetMessageAttributes(MailMessage message, SendEmailData data, FormSubmitContext formSubmitContext) at Sitecore.ExperienceForms.Mvc.Processing.SubmitActions.SendEmail.Execute(SendEmailData data, FormSubmitContext formSubmitContext)

To Reproduce

  1. add recaptcha module to a form
  2. try to submit it

We are using the 4.0.2

dbalosetti commented 2 years ago

i would like to add that we have noticed that it happens only when is present also send email submit action

asontu commented 2 years ago

Sounds you are on Sitecore version 10.0 or earlier. The GetStringValue() method that SFE 4.0+ relies on was introduced in 10.1

Confirm which Sitecore version you're on (Desktop -> All Applications -> System -> License details) and install the latest SFE 3 version for 9.x or 10.0

klawingco commented 2 years ago

Hmm We got this too, We are on Sitecore 10.1. Tried to downgrade to 3.2 and still the same. @asontu

klawingco commented 2 years ago

Coming back here for a possible fix. You don't need to downgrade. TLDR: Inherit and Modify.

This only happens on SendEmail because SendEmail calls ReflectionUtil.CallMethod((object) postedField, "GetStringValue").ToString();

Which we don't have any implemented at ReCaptchaModel

So there are two possible ways to fix this

  1. If you installed SFE directly at your solution all you need to do is to inherit RecapCha modal and add a function GetStringValue

Then change the model path from Content Tree at Sitecore Settings e.g

    public class CustomReCaptchaModel : ReCaptchaModel 
    {
     .... 
     public string GetStringValue(){
         return String.empty;
      }
    }
  1. Is if you are using SFE as a Container Module (like in my case). Its a bit more tricky but since you wouldnt have access to override ReCaptchaModel, You will need to customize the SendEmail Actions 2.1. First is create a SubmitAction that inherits the SendEmail. Most of the codes here are lifted from SendEmail using dotPeek.
    See the full gist here https://gist.github.com/klawingco/82a29f6c72933427d615e2d38a84315f Basically is adding a try and catch at ReflectionUtil.CallMethod((object) postedField, "GetStringValue").ToString(); will suffice, however you could also just use the GetMethod to conditionally check it. 2.2 Make sure to edit your Form Submit Action Item to point to your custom SubmitActions which typically sits at /sitecore/system/Settings/Forms/Submit Actions/

And that's it!. Your Send Email Action will now work fine.