Copied to clipboard

Flag this post as spam?

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


  • Adam Maidment 54 posts 163 karma points
    Jul 04, 2013 @ 12:25
    Adam Maidment
    0

    Send XSLT Transformed Email to emails stored in node properties

    Hi,

    We have a simple email sign up form which takes usual personal details, including a venue selection dropdown list.

    We'd like the from to send these captured details onto the selected venue. Each venue exists as a node and has a property "venueEmailAddress" which contains their email address.

    In the past with fixed forms we've justed used a variation the following code to detect which venue has been selected and then forward the email on:

    <xsl:choose>
          <xsl:when test="$venueValue = 'London'">
            <xsl:value-of select="umbraco.library:SendMail('[email protected]', '[email protected], 'Subject Line', $bodyText, 'true')"/>
          </xsl:when>
    </xsl:choose>

    We could do this again, but the site will grow and many more venues are st to be added, so we don't want to have to manually adjust this code for each new venue.

    If we could just get the ID of the selected node (we're using a Prevalue Source) then we could grab the property value for "venueEmailAddress" and feed this into SendMail(). However I'm struggling to pull out the ID and can only seem to get the value (name) of each venue.

    Does anyone have any suggestions? Perhaps I'm thinking about this all wrong.

    Many thanks

    Adam

  • Comment author was deleted

    Jul 04, 2013 @ 12:39

    Hey Adam

    Could you tell me if you are using the usercontrol or razor macro, depending on that I can give you some tips :)

  • Adam Maidment 54 posts 163 karma points
    Jul 04, 2013 @ 12:42
    Adam Maidment
    0

    Hi Tim,

    Using XSLT running on the "form submitted" action within Contour.

     

  • Comment author was deleted

    Jul 04, 2013 @ 12:44

    Yeah that's the workflow but how are you inserting the form on your pages? Or maybe you are running an older Contour version (before v3) that only has the usercontrol macro

  • Adam Maidment 54 posts 163 karma points
    Jul 04, 2013 @ 12:51
    Adam Maidment
    0

    As of yet none - I'm just testing atm ;-) but I'll be using the RazorRenderForm macro.

    Happy to use either depending on what solution you have.

  • Comment author was deleted

    Jul 04, 2013 @ 12:58

    Ok :) well the razor one offers more flexibility, will do some tests and get back to you with some advice :)

  • Adam Maidment 54 posts 163 karma points
    Jul 04, 2013 @ 13:01
    Adam Maidment
    0

    Excellent thanks Tim, appreciate it!

  • Comment author was deleted

    Jul 04, 2013 @ 16:07

    Ok several ways to do this but think this will be easiest:

    Update the dropdown view so it also includes the id in the value, maybe seperated with | (so it's easy to split afterwards)

    Details on customizing the views can be found here http://our.umbraco.org/projects/umbraco-pro/contour/documentation/Developer/Custom-Markup/

    Now in you xslt that transforms the mail, fetch the id from the value (splitting on the | ) and use that id to fetch the node by id 

    http://our.umbraco.org/wiki/reference/umbracolibrary/getxmlnodebyid-(1)

    And from that you should be able to fetch the property you want

    Make sense?

  • Adam Maidment 54 posts 163 karma points
    Jul 04, 2013 @ 16:09
    Adam Maidment
    0

    Perfect sense. Thanks Tim. I'll give this a go and let you know how I get on. 

  • Comment author was deleted

    Jul 04, 2013 @ 16:20

    Cool hope you get it working :)

  • Adam Maidment 54 posts 163 karma points
    Jul 04, 2013 @ 16:48
    Adam Maidment
    0

    OK here's where I am:

    FieldType.DropDownList.cshtml under Umbraco>Plugins>umbracoContour>Views changed to:

    @model Umbraco.Forms.Mvc.Models.FieldViewModel
    <select name="@Model.Name" id="@Model.Id"
    @if (Model.Mandatory){<text> data-val="true" data-val-required="@Model.RequiredErrorMessage"</text>}>
        <option value="-- Select an option --"></option>
        @foreach (var pv in Model.PreValues)    {
            <option value="@pv.Id" 
            @if (Model.ContainsValue(pv.Value))
            {<text>selected="selected"</text>}
            >@pv.Value</option>
        }
    </select>

    which is outputting a nice ddl with the ID of the nodes as the option values:

    <select id="faacb8eb-8b10-44bd-a351-5361f07ae11e" class="valid" data-val-required="Please select a venue" data-val="true" name="faacb8eb-8b10-44bd-a351-5361f07ae11e">
    <option value="-- Select an option --"></option>
    <option value="1118">Aylesbury</option>
    <option value="1577">Belfast</option>
    <option value="1578">Birmingham</option>
    <option value="1579">Brentwood</option>
    ...
    in the XSLT i currently have:
    <xsl:variable name="venueValue" select="$records//fields/child::* [caption = 'Venue']//value"/>
    <xsl:variable name="node" select="umbraco.library:GetXmlNodeById($venueValue)" />

    <!-- Output venue email address (test) -->
    <xsl:value-of select="$node/venueEmailAddress"/>

    <!-- TEST OUTPUT -->
    <xsl:value-of select="$venueValue"/> 

    However when testing the the value is still the venue name (eg London, Bristol, Chester etc) and not the ID.

    Have I missed a step or does the XSLT need to be adjusted?

  • Adam Maidment 54 posts 163 karma points
    Jul 04, 2013 @ 17:09
    Adam Maidment
    0

    I suppose the other question is, is it possible in XSLT to get the ID of a node by using the node name?

  • Adam Maidment 54 posts 163 karma points
    Jul 04, 2013 @ 17:42
    Adam Maidment
    0

    Tim.

    I should have just listened to you closely in the first place! When replacing the option value with either id or value, the value is saved in the database. When a different string is used, ie 

    <option value="@pv.Value  (@pv.Id)" 

    all is well and you can then split the string as you suggested.

    Final code for others, if it helps:

    @model Umbraco.Forms.Mvc.Models.FieldViewModel
    <select name="@Model.Name" id="@Model.Id"
    @if (Model.Mandatory){<text> data-val="true" data-val-required="@Model.RequiredErrorMessage"</text>}
    >
        <option value="-- Select an option --"></option>
        @foreach (var pv in Model.PreValues)
        {
            <option value="@pv.Value  (@pv.Id)" 
            @if (Model.ContainsValue(pv.Value))
            {<text>selected="selected"</text>}
            >@pv.Value</option>
        }
    </select>
    <xsl:variable name="venueValue" select="$records//fields/child::* [caption = 'Venue']//value"/>
    <xsl:variable name="first" select="substring-before($venueValue, ')')" /> 
    <xsl:variable name="remaining" select="substring-after($first, '(')" /> <xsl:variable name="node" select="umbraco.library:GetXmlNodeById($remaining)" />
    <xsl:value-of select="$node/clubEmailAddress"/> 

    Thanks for your assistance Tim. I just need to pull the email address into SendMail() now and I'm done!

     

  • Comment author was deleted

    Jul 04, 2013 @ 17:45

    Great :)

Please Sign in or register to post replies

Write your reply to:

Draft