Copied to clipboard

Flag this post as spam?

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


  • Ilia 2 posts 22 karma points
    Oct 30, 2013 @ 18:06
    Ilia
    0

    Trouble changing parameter values via document type fields

    I'm new to Umbraco and packages so I apologize if I'm just missing something really basic.

    But I'm having trouble changing the values of the macro parameters using the document type parameters. This is what I'm doing...

    Following the documentation I have a template into which I put the following code

    <umbraco:Macro FileLocation="~/macroScripts/CultivContactForm.cshtml" runat="server" FormLabelEmail="asd" />

    It's missng the MailFrom parameters because I wanted to set it via document type (the FormLabelEmail is there to just verify I can modify parameters "manually"). So then in the document type for contact form I've created a field to modify the text for the name label. Here's a screenshot

    As you can see I've given it the formLabelName alias.

    I then set the value of that field to "Your Name:" when editing the content for the contact page. However, when I refresh the actual contact page this is how the form looks.

    So as you can see it doesn't look like the parameter got the value from the document type field, but I can't see what I could've done wrong.

    Any help would be appreciated, thank you.

  • Ilia 2 posts 22 karma points
    Oct 30, 2013 @ 19:59
    Ilia
    0

    Okay, so after digging around in CultivContactForm.cshtml I realized that the plugin simply doesn't support that kinda functionality for any parameters but "mail from" and "mail from name".

    So if somebody out there is having a similiar issues and wants to be able to change value of other parameters via document type here's how you do it.

    In CultivContactForm.cshtml there is a class/function FormVariables. You'll notice that the MailFrom and MailFromName are handled slightly differently from the rest. Specifically their alternate value (i.e. the Y in MailFrom = X ?? Y) actually comes from a previous variable (modelMailFrom in this case) that was assigned value from the model (model.MailFrom), which references the document type fields.

    So to add, for example, the same functionality for the name label field you need to do two things. First add a variable at the top like this

    var nameLabel = model.FormLabelName.GetType() != typeof(umbraco.MacroEngines.DynamicNull) ? model.FormLabelName : "Name";

    "FormLabelName" would be the field name you use when creating the parameter for the document type. And then for the Name vaiable modify the line to be this

    Name = GetParamValue(parameter.FormLabelName) ?? GetParamValue(nameLabel);

    And Bob's your uncle.

Please Sign in or register to post replies

Write your reply to:

Draft