Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • mizzle 90 posts 325 karma points
    Feb 25, 2021 @ 17:55
    mizzle
    0

    Direct MVC form to certain email addresses depending on dropdown selection?

    I have a very basic MVC contact form setup, with the addition of customizable dropdown menu options that have been set up as Nested Content items on my form's page. I just pull the dropdown options from a text field on the nested content items.

    I would like to link these options to email addresses (also editable in Umbraco, likely as another field within the dropdown menu option Nested Content item) that would receive the form, based on the end user selecting something in the dropdown.

    Is there a simple way to do this?

  • Mehmet Avcı 55 posts 240 karma points
    Mar 01, 2021 @ 14:18
    Mehmet Avcı
    0

    Hi,

    First thing comes up to my mind is; adding another property to that nested content type to get email info in either single text or a list.

    Then, whenever your form is post, you can re-read that nested content items, match your dropdown value and send your email. Sounds like it should work.

    -Best

    Mehmet

  • mizzle 90 posts 325 karma points
    Mar 01, 2021 @ 14:35
    mizzle
    0

    That sounds like what I want to do, but I'm blanking on how to match up the dropdown value with the nested content item before the email for the form is sent off.

    Sorry, my grasp on MVC forms is pretty limited. I'm not sure where anything really goes or how to make adjustments to them. Just getting the dropdown fields working took me some time of trial and error.

  • Mehmet Avcı 55 posts 240 karma points
    Mar 01, 2021 @ 15:24
    Mehmet Avcı
    100

    Hi again,

    I strongly advise you to first follow up a simple mvc form tutorial first. There is one which I believe explains it clearly on this page.

    On umbraco, it follows up same logic with a similar ruleset, mostly different names points to different things. In umbraco, for basic MVC form submission a specific type of controller is used, which is called Surface Controller. Documentation about that one is here.

    Once you get going with these 2, it is fairly simple to follow up on your request. Simply your action in controller should look like this.

        public ActionResult FormSubmitAction(ContactFormModel model)
        {
            //First check if your model is valid
            //This uses DataAnnotations and checks your model in the paramater.
            if (ModelState.IsValid)
            {
                /**
                 * CurrentPage gives you current page you're on
                 * Considering your nested content property is on the page, you should be able to access it also.
                 */
                var nestedContents = CurrentPage.GetPropertyValue<List<IPublishedContent>>("yourNestedPropertyAlias");
    
    
                // Since now you have nested contents, query it down by your property in the form, given the data
                var matchedContent = nestedContents.FirstOrDefault(x => x.GetPropertyValue<string>("subjectAlias") == model.Subject);
    
                var emailAddress = matchedContent.GetPropertyValue<string>("emailPropAlias");
    
                //SMTP logic should follow it down.
    
            }
        }
    

    I hope these would help. Of course these would require a basic understanding of coding and c# first, then mvc can follow up.

    Good luck!

Please Sign in or register to post replies

Write your reply to:

Draft