Copied to clipboard

Flag this post as spam?

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


  • Arlan 58 posts 184 karma points
    Aug 11, 2015 @ 01:03
    Arlan
    0

    Pass CurrentPage.Name as Hidden value via form

    I have a form that i can add using Rich Text Editor via Macro, i want to include CurrentPage.Name as hidden value that is passed on submit

    what would be the syntax for it? something like @{ var currentPageName = CurrentPage.Name; }

    @HtmlHiddenFor(???, currentPageName??)

    here is working code i have currently without passing hiddenvalue

    Partial

        @model Pro_Ghetto_Events.Models.FormEventPageModel
    
               @{
    
               }
    @if (TempData["success"] == null)
    {
        using (Html.BeginUmbracoForm("Submit", "FormEventPage", new { enctype = "multipart/form-data" }))
        {
    
            <div class="small-12 medium-6 columns">
                @Html.LabelFor(x => x.Name)
                @Html.TextBoxFor(x => x.Name)
                @Html.ValidationMessageFor(x => x.Name, "", new { @class = "error" })
            </div>
            <div class="small-12 medium-6 columns">
                @Html.LabelFor(x => x.Email)
                @Html.TextBoxFor(x => x.Email)
                @Html.ValidationMessageFor(x => x.Email, "", new { @class = "error" })
            </div>
            <div class="small-12 medium-6 columns">
                @Html.LabelFor(x => x.Phone)
                @Html.TextBoxFor(x => x.Phone)
                @Html.ValidationMessageFor(x => x.Phone)
            </div>
            <div class="small-12 medium-6 columns">
                @Html.LabelFor(x => x.NumberOfGuests)
                @Html.TextBoxFor(x => x.NumberOfGuests)
                @Html.ValidationMessageFor(x => x.NumberOfGuests)
            </div>
        <div class="small-12 columns">
                @Html.LabelFor(x => x.NeedTickets)
                @Html.CheckBoxFor(x => x.NeedTickets)
            </div>
            <div class="small-12 columns" style="margin-top:15px;">
                <input type="submit" value="Submit" class="button radius" />
            </div>
        }
    }
    else
    {
        <section class="lead">
            <p>Thank you for your request</p>
            <p>We have received your message and would like to thank you for writing to us.</p>
        </section>
    }
    

    Model

     using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Web;
    using System.Web.Http;
    
    namespace Pro_Ghetto_Events.Models
    {
        public class FormEventPageModel
        {
            [Required]
            public string Name { get; set; }
            [Required]
            [EmailAddress]
            public string Email { get; set; }
            public string Phone { get; set; }
            [DisplayName("Number Of Guests")]
            public string NumberOfGuests { get; set; }
            [DisplayName("Do you need tickets for this event?")]
            public bool NeedTickets { get; set; }
            public string PageName { get; set; }
        }
    }
    

    i am guessing i need to add for sure, HiddenFor in Partial and maybe public string in Models?

    how woult that look in the cod?

  • Per Olsson 47 posts 307 karma points
    Aug 11, 2015 @ 06:21
    Per Olsson
    0

    The following should do the trick:

    <input type="hidden" value="@CurrentPage.Name" />
    
  • Arlan 58 posts 184 karma points
    Aug 12, 2015 @ 21:52
    Arlan
    0

    thanks, another way is to just add this in controller:

    var currentNode = Umbraco.TypedContent(UmbracoContext.PageId.GetValueOrDefault());
    .
    .
    .
    message.Body += "<p><strong>Event Name</strong><br>" + currentNode.Name + "</p>";
                message.Body += "<p><strong>Event Page</strong><br>" + @Umbraco.NiceUrlWithDomain(currentNode.Id) + "</p>";
    
Please Sign in or register to post replies

Write your reply to:

Draft