Copied to clipboard

Flag this post as spam?

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


  • Edgar Rasquin 326 posts 925 karma points
    Mar 03, 2017 @ 08:47
    Edgar Rasquin
    0

    Options List in a contact form

    Hi there,

    I am stuck with a problem:

    I have a Contact Form in an partial view. Now I need a 2-level List where different options can be picked:

    enter image description here

    Any ideas?

  • Shola 65 posts 273 karma points
    Mar 03, 2017 @ 18:03
    Shola
    0

    You should use conditions when you're setting up the checkbox lists. For a checkbox list, you want to only show it if the dropdown has a specific value correct?

    enter image description here

  • Edgar Rasquin 326 posts 925 karma points
    Mar 06, 2017 @ 08:18
    Edgar Rasquin
    0

    Hi Shola,

    thanks for your reply. As far as I understand this is part of Umraco Forms. I'm not using Umbraco Forms.

    By now I managed to get to show the Kategory - Skills level structure by simply Building an own node on home level and displaying these in a foreach Loop in my form.

    enter image description here

    Here is my Code in the _contactEx.cshtml

    <div class="col_full col_last">
            @{
                var rootNodes = Umbraco.TypedContentAtRoot();
                //var homeNodeByAlias = rootNodes.First(x => x.DocumentTypeAlias == "category");
                var homeNodeById = rootNodes.First(x => x.Id == 1478);
                var kategories = homeNodeById.Children;
    
    
    
                foreach (var kat in kategories)
                {
                    if (kat.Children.Any())
                    {
                        TempData["kat"] = @kat.Name;
                        <div class="toggle toggle-border">
                            <div class="togglet"><i class="toggle-closed icon-ok-circle"></i><i class="toggle-open icon-remove-circle"></i>@kat.Name</div>
                            @skills(kat.Children)
                        </div>
    
                    }
                }
    
                @helper skills(dynamic pages)
                {
    
                    var skillName = "";
    
                    <div class="togglec" style="display: none;">
                        @foreach (var page in pages)
                        {
                            skillName = String.Format("{0}-{1}", TempData["kat"], @page.Name);
                            <div>
                                <input id="@skillName" class="checkbox-style" name="Skills" type="checkbox" value="@skillName" checked>
                                <label for="@skillName" class="checkbox-style-3-label checkbox-small">@page.Name</label>
                            </div>
                        }
                    </div>
    
                }
            }
        </div>
    

    My Problem now is how to get the values of the checkboxes in my controller.

    Any ideas?

  • Edgar Rasquin 326 posts 925 karma points
    Mar 06, 2017 @ 09:39
    Edgar Rasquin
    0

    OK, solved!

    for collecting the hardcoded checkbox values in the controller you just need to keep the name of the checkboxes the same.

    First you write the following line in the Model:

    model.cs:

    public IEnumerable<string> Skills { get; set; }
    

    In your form.cshtml you create your checkboxes, make shure the name attribute stays the same for all checkboxes:

    form.cshtml:

     <input id="@skillName" class="checkbox-style" name="Skills" type="checkbox" value="@skillName">
    

    In your controller.cs you just need to collect the value and like in my example Loop through the values to write them in the response email body:

    Controller.cs:

    //Skills
                int skillCount = 0;
    
    
    
                foreach (var skill in model.Skills)
                {
                    message.Body += "<br>";
                    message.Body += "Skill" + skillCount + ":" + skill + "<br>";
                    skillCount++;
                }
    

    Cheers

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies