Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Problem with Episerver Forms

Vote:
 

I have hard time sending mails ater submission of Forms and executing a controller to process payment.

I have configured the webconfig for SMTP but still i am not receiving mails sent from EPiserver Forms.

#194131
Edited, Jun 14, 2018 10:35
Vote:
 

Hi, Himshikhar,

Have you checked out the log files? Is there an error logged?

I usually use smtp4dev with default settings or specify a pickup directory:

      <smtp from="no-reply@example.com" deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="c:\temp\maildrop" />
      </smtp>

Just to check if there is no error in setup or logic. If it still doesn't work, you'll need to get the error from the log file.

BR,
Marija

#194231
Jun 16, 2018 19:54
Vote:
 

Hi Marija ,

it didn't worked . But can you please elabarote the logging part.

#194268
Jun 18, 2018 15:00
Vote:
 

Hey,

Please check how to set up logging in the documentation:

https://world.episerver.com/documentation/developer-guides/CMS/logging/logging-with-log4net/

BR,
Marija

#194272
Jun 18, 2018 15:24
Vote:
 

Thanks Marija

#194429
Jun 21, 2018 8:46
Vote:
 

The best way to work with EPiserver Forms is to add a Initialization module and handle them as Form submission eventhandling.

We can read the data of the form before submitting and after submission . So in this manner we can update ot on the fly while form is not submitted but is to be submitted,

Eg;

public class FormsEventsInitModule : IInitializableModule
    {
        private Injected<IFormRepository> _formRepository;
        private Injected<IContentRepository> _contentRepository;
        private Injected<UrlResolver> _urlResolver;
        protected ServiceConfigurationContext _serviceConfigurationContext;
        private static readonly ILogger _logger = LogManager.GetLogger(typeof(FormsEventsInitModule));
        string MerchantId
        {
            get { return ConfigurationManager.AppSettings["merchantId"]; }
        }
        string Token
        {
            get { return ConfigurationManager.AppSettings["token"]; }
        }
        string TerminalUrl
        {
            get { return ConfigurationManager.AppSettings["terminalUrl"]; }
        }
        public string RedirectUrl { get; set; }
        public string ExternalRef { get; set; }
        public void Initialize(InitializationEngine context)
        {
            // get the Forms Event Manager
           var formsEvents = ServiceLocator.Current.GetInstance<FormsEvents>();
            // listen to its events
            formsEvents.FormsStructureChange += OnStructureChange;
            formsEvents.FormsSubmitting += OnSubmitting1;
            formsEvents.FormsSubmitting += OnSubmitting2;
            formsEvents.FormsStepSubmitted += OnStepSubmit;
            formsEvents.FormsSubmissionFinalized += OnFormFinalized;           
        }
      
        private void OnFormFinalized(object sender, FormsEventArgs e)
        {
           
        }
        private void OnStepSubmit(object sender, FormsEventArgs e)
        {
           
        }
        private void OnSubmitting1(object sender, FormsEventArgs e)
        {
            _logger.Critical("You are submitting Form:{0}[{1}]", e.FormsContent.Name, e.FormsContent.ContentGuid);
        }
        private void OnSubmitting2(object sender, FormsEventArgs args)
        {
            var e = args as FormsSubmittingEventArgs;
            var guid = e.FormsContent.ContentGuid;
            var formContent = e.FormsContent as FormContainerBlock;
            var redirectUrlForm = formContent.RedirectToPage;
            //var currentPageData = e.SubmissionData.Data;
            //var currentPageId = currentPageData["SYSTEMCOLUMN_HostedPage"];
            //var pageRef = new PageReference(currentPageId.ToString());
            //var page = _contentRepository.Service.Get<PageData>(pageRef);
            var elementCollection = _formRepository.Service.GetDataFriendlyNameInfos(new FormIdentity(guid, null));          

            var elementPayment = elementCollection.FirstOrDefault(x => x.FriendlyName == "Payment");
            if (elementPayment != null)
            {
                var elementName = elementCollection.FirstOrDefault(x => x.FriendlyName == "Name");
                var elementEmail = elementCollection.FirstOrDefault(x => x.FriendlyName == "Email");
                var elementTransactionId = elementCollection.FirstOrDefault(x => x.FriendlyName == "transactionId");
               
                //var paymentPage = page as PaymentPage;               
                RedirectUrl = string.Format("{0}{1}?__FormGuid={2}", ConfigurationManager.AppSettings["redirectUrl"], _urlResolver.Service.GetUrl(redirectUrlForm.ToString()), guid.ToString());
                var paymentOption = e.SubmissionData.Data.FirstOrDefault(x => x.Key == elementPayment.ElementId);
                var NameOption = e.SubmissionData.Data.FirstOrDefault(x => x.Key == elementName.ElementId);
                var EmailOption = e.SubmissionData.Data.FirstOrDefault(x => x.Key == elementEmail.ElementId);
                var TransactionIdOption = e.SubmissionData.Data.FirstOrDefault(x => x.Key == elementTransactionId.ElementId);

                string orderCurrencyCode = ConfigurationManager.AppSettings["DefaultCurrency"];
                string OrderName = NameOption.Value.ToString().ToLower().Replace("æ", "ae").Replace("ø", "oe").Replace("å", "aa");
                OrderName = cefor.Business.Utils.CeforUtils.RemoveDiacritics(OrderName);
                OrderName = (OrderName.Substring(OrderName.LastIndexOf(' ') + 1) + DateTime.Now.Day + DateTime.Now.Minute).Replace(" ", "");
                string Amount = "0";
                if (paymentOption.Value.ToString().Contains("¤"))
                {
                    string[] selectedOrderPaymentOptions = paymentOption.Value.ToString().Split('¤');
                    var price = selectedOrderPaymentOptions[1];
                    int sum = Convert.ToInt32(price) * 100;
                    Amount = sum.ToString("0");
                    if (selectedOrderPaymentOptions.Length > 2)
                    {
                        orderCurrencyCode = selectedOrderPaymentOptions[2];
                    }
                }
                string PaymentReady = PreparePayment(OrderName, Amount, orderCurrencyCode);
                if (!string.IsNullOrEmpty(PaymentReady))
                {
                    e.CancelAction = true;
                    e.CancelReason = PaymentReady;
                }
                else
                {
                    TransactionIdOption = new KeyValuePair<string, object>(TransactionIdOption.Key, ExternalRef);
                    e.SubmissionData.Data.Remove(TransactionIdOption.Key);
                    e.SubmissionData.Data.Add(TransactionIdOption);
                }
                //GoToPayment();
            }
        }
#194549
Jun 25, 2018 12:56
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.