Copied to clipboard

Flag this post as spam?

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


  • Jay Crowe 42 posts 173 karma points
    Oct 22, 2018 @ 13:30
    Jay Crowe
    0

    Formulate: Populate form field from a parameter

    Hi,

    Is there a way to populate form fields and make them read only? I basically have a form and I want to pre populate a field and then set that field to be read only.

    Cheers, Jay

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Oct 22, 2018 @ 16:48
    Nicholas Westby
    0

    Hi Jay,

    Depends on your use case. Here is one option:

    Text Constant Field

    The text constant field in Formulate is useful for situations where you want to send a field to an API using the send data form submission handler. You just type in a value on the server and that is the value that will be included as if the user had typed it into the form:

    Example Text Constant Field

    Not sure if that answers your question. If not, let me know a bit more about what you're trying to accomplish.

  • Jay Crowe 42 posts 173 karma points
    Oct 22, 2018 @ 19:55
    Jay Crowe
    0

    Hi Nicholas,

    Thank you for your reply.

    Basically I have a job vacancy page and an Apply button which when clicked displays a formulate form which allows them to submit their information along with their CV to effectively apply for that advertised job.

    I would like to populate the Job Title field on the form with the Job Title from the advert. So it is pre populated for them and make it read only.

    They will then submit that form once all of the details have been completed which is sent to my clients email address.

    Regards, Jay

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Oct 22, 2018 @ 20:37
    Nicholas Westby
    1

    I see. So you'll need to set the "Job Title" field to some text programmatically, and that field should not be editable.

    You may want to use the "Header" or the "Rich Text" field. You can then populate the value when the form renders. You can do that here (assuming you are using the AngularJS template): https://github.com/rhythmagency/formulate/blob/1e270588ef73d86d85477dbde0686f905d1774b8/src/Website/Views/Partials/Formulate/Responsive.Bootstrap.Angular.cshtml#L79

    Right now, it sets the text to the configured value. You can instead set the text to some other value (e.g., you can fetch it from a property on the current page or something of that sort). And you can do this conditionally (e.g., depending on what the category is for the field). That is, you might have a field category of "Job Title" that, when present, will cause the rich text to be set to the job title rather than the configured text value.

    Note that rich text fields may not be propagated via the form submission, so you may want to also store the job title in a hidden field (you can use a similar approach to set the hidden field value).

  • Jay Crowe 42 posts 173 karma points
    Oct 23, 2018 @ 12:51
    Jay Crowe
    0

    That's great thank you for your reply I will try that.

    One last question. Is there a way I can set which form to display without having to select one from a form picker? It will be the same form displayed on all of the Vacancy pages on my site so rather than having to select it for everything Vacancy page I create I would just rather hard code it?

  • Jay Crowe 42 posts 173 karma points
    Oct 23, 2018 @ 13:34
    Jay Crowe
    0

    Also within the Responsive.Bootstrap.Angular.cshtml im not sure how I can get the property from the page the form is rendered on?

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Oct 23, 2018 @ 19:40
    Nicholas Westby
    1

    Also within the Responsive.Bootstrap.Angular.cshtml im not sure how I can get the property from the page the form is rendered on?

    Something like this:

    var currentPage = UmbracoContext.Current.PublishedContentRequest.PublishedContent;
    var someValue = currentPage.GetPropertyValue<string>("someProperty");
    

    Bit hacky, but should work.

  • Jay Crowe 42 posts 173 karma points
    Oct 24, 2018 @ 16:07
    Jay Crowe
    0

    I can now get the page value to show so thank you for your help.

    I cannot get the label to show for the rich text editor or get it to show as part of the submission.

    Do you have examples of setting a hidden field and getting it to show with the rest of the submitted data?

    Thanks, Jay

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Oct 24, 2018 @ 18:21
    Nicholas Westby
    100

    I cannot get the label to show for the rich text editor or get it to show as part of the submission.

    That field does not show the label (since it rarely makes sense to have some rich text that has some more text describing it).

    And I believe I built that field without the rich text as part of the submission intentionally since rich text is usually just used for display purposes (hence the suggestion to separately set the text in the hidden field).

    Do you have examples of setting a hidden field and getting it to show with the rest of the submitted data?

    First, add this to the top of the file:

    @using formulate.app.Forms.Fields.Hidden
    

    Then you'll change this:

    // The initial value comes from the query string based on the field alias.
    initialValue = string.IsNullOrWhiteSpace(x.Alias)
        ? null
        : Request.QueryString[x.Alias],
    

    To something like this:

    initialValue = x.FieldType == typeof(HiddenField)
        ? "Special Value For Hidden Field"
        : null,
    

    Use whatever logic makes sense for your situation.

  • Lasse Kofoed 49 posts 177 karma points
    Aug 29, 2019 @ 11:07
    Lasse Kofoed
    0

    Hi Nicholas

    Im on 8.1.2 Umbraco using Formulate 3.0.0

    I can't seem to get the prevalue from querystring to work.

    field alias = subject ?subject=420

    using Plan Javascript, any hints to what might be wrong ?

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Aug 29, 2019 @ 16:59
    Nicholas Westby
    0

    I suspect that was only ever implemented for the AngularJS template.

    It should be relatively straightforward to implement this for the plain JavaScript template.

    It looks like the "initialValue" is already being passed to the JavaScript via the JSON here: https://github.com/rhythmagency/formulate/blob/3004d968b4cc67f9663f6567c0babe9a08a7d41d/src/Website/Views/Partials/Formulate/Responsive.Plain%20JavaScript.cshtml#L176-L178

    So you'd want to modify the JavaScript to recognize this value and set the value on the DOM element for the input. You could probably do that around here: https://github.com/rhythmagency/formulate/blob/3004d968b4cc67f9663f6567c0babe9a08a7d41d/src/formulate.frontend/responsive.plain-javascript/utils/field.js#L84

    Life's a bit busy for me right now, so that's pretty much all the help I can offer. Good luck, and feel free to submit a pull request if you would like this to be integrated into the core of Formulate (though you can also make all these changes outside of the core of Formulate if you like too).

  • Jay Crowe 42 posts 173 karma points
    Oct 25, 2018 @ 13:16
    Jay Crowe
    1

    Perfect thank you for your help Nicholas. Much appreciated!

    P.s formulate is awesome!

Please Sign in or register to post replies

Write your reply to:

Draft