1

How do I fire a submit event in server side from the Sitecore SXA form and apply business logic?

I am using Sitecore Form in which i have addded two text box and one button and i want to fire button event and save the textbox data in a list object and then show that data from the list object to a Column Chart how can i achieve that.?

  • Please add more details of your current implementation. – Bartłomiej Mucha Aug 29 '19 at 6:28
  • I am using Sitecore Form in which i have addded two text box and one button and i want to fire button event and save the textbox data in a list object and then show that data from the list object to a Column Chart how can i achieve that.? – Sunny Kumar Aug 29 '19 at 10:14
1

To Achieve the Custom Submit event you have to create your Custom Event please follow the below steps:

1) Add class in your project and Inherit with SubmitActionBase

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

        protected override bool Execute(string data, FormSubmitContext formSubmitContext)
        {
//to get the form values
 foreach (var viewModel in formSubmitContext.Fields)
            {

  PropertyInfo property = postedField.GetType().GetProperty("Value"); //value property
                object postedValue =
                    (object)property != null ? property.GetValue((object)postedField) : (object)null; //get value

                property = postedField.GetType().GetProperty("Title"); //title property

                object postedTitle =
                    (object)property != null ? property.GetValue((object)postedField) : (object)null;//title value
                string title = postedTitle?.ToString();

                var postedFieldName = ((Sitecore.ExperienceForms.Mvc.Models.Fields.FieldViewModel)postedField).TemplateId;

}
// now you have your form fields values now you can use your logic here

}
}

2) once you done with this now you have to add your custom action in your sitecore, follow below image to add Submit Action Template.

enter image description here

3) When you add new Submit Action Template, give an appropriate name and assign the below values: enter image description here

4) once you done this you will find your submit action in Submit actions

enter image description here

Hope this will helps you.

  • its Working fine but The Execute Method is not getting Executed and to achieve that what do i need to do any help would be appreciated Thanx. – Sunny Kumar Sep 3 '19 at 5:07
  • It should work, make sure your class is inherit from SubmitActionBase and you have correctly assign the Model as per Point 3 – Sunil Kumar Sep 3 '19 at 7:11
  • Point 3 Image doesn't open in my browser can you please make it visible for me so that i can check and will fix the problem. – Sunny Kumar Sep 3 '19 at 12:30
  • If you want to get the path you can follow image 2, here is clear view of image 3 : ibb.co/gZQhHwj – Sunil Kumar Sep 3 '19 at 13:26

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