0

I'm getting user name and mail id through sitecore form. on clicking submit the sitecore form submit action has to get triggered. In turn the following code has to get triggered. But the debug point is not hitting. But its showing the thank you message which i have mentioned in the sitecore form. I need to create a contact using the given user credentials which i'll be viewing in Experience profile. Since the code is not getting triggered the contacts are not getting saved so i can't view them in Experience Profile. Kindly suggest me some solutions. Thanks in advance.

public class LoginFormSubmit : SubmitActionBase<string>
    {
        public LoginFormSubmit(ISubmitActionData submitActionData) : base(submitActionData)
        {

        }
        protected override bool TryParse(string data, out string target)
        {
            target = string.Empty;
            return true;
        }
        //Override the Execute method to insert data to API
        protected override bool Execute(string data, FormSubmitContext formSubmitContext)
        {
            ApiModel customData = new ApiModel();
            try
            {
                Log.Info("FormSubmit Execute Method Started..", typeof(FormSubmit));
                var firstNameField = GetFieldByName(ApiConstants.FirstName, formSubmitContext.Fields);
                customData.First_Name__c = GetValue(firstNameField);

                var emailField = GetFieldByName(ApiConstants.Email, formSubmitContext.Fields);
                customData.Email__c = GetValue(emailField);

                CreateContact contact = new CreateContact();
                contact.CreateContactBasedOnSession(customData.First_Name__c, customData.Email__c);

                return true;
            }
            catch (Exception e)
            {
                Log.Error("Login Save:", e, typeof(FormSubmit));
                Log.Error(string.Concat("Login save", e.Message.ToString()), typeof(FormSubmit));
                return false;
            }
        }
        private static IViewModel GetFieldByName(string fieldName, IList<IViewModel> fields)
        {
            return fields?.FirstOrDefault(f => f.Name == fieldName) != null ? fields.FirstOrDefault(f => f.Name == fieldName) : null;
        }
        private static string GetValue(object field)
        {
            return field?.GetType().GetProperty("Value")?.GetValue(field, null)?.ToString() ?? string.Empty;
        }
    }

enter image description here

8
  • Welcome to Sitecore Stack Exchange. How did you create the custom form action in sitecore? Does it inherit from /System/Forms/Submit Action template, also the Model Type field is correctly setup with your class name and the action is assigned to the form? Jul 13 at 14:58
  • I have added the image link for your reference. i.stack.imgur.com/2XKyo.png
    – Indu Mathi
    Jul 13 at 15:27
  • I assume that the custom action is also added to the form and you are using ajax post, are you getting any errors in the log files when submitting the form? Also in visual studio you are seeing the red breaking point correctly, right? Jul 13 at 15:43
  • Welcome to Sitecore stack exchange, make sure you deployed the dll from debug mode Jul 13 at 22:09
  • 1
    Can you try setting the value in your ModelType without the assembly name, like Prudential.Feature.Forms.Models.Product_Form.LoginFormSubmit and see if there is any difference or error happening in log files aswell? Jul 14 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.