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.
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:
Not sure if that answers your question. If not, let me know a bit more about what you're trying to accomplish.
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.
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).
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?
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");
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.
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).
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
Hi Jay,
Depends on your use case. Here is one option:
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:
Not sure if that answers your question. If not, let me know a bit more about what you're trying to accomplish.
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
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).
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?
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:
Bit hacky, but should work.
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
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).
First, add this to the top of the file:
Then you'll change this:
To something like this:
Use whatever logic makes sense for your situation.
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 ?
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).
Perfect thank you for your help Nicholas. Much appreciated!
P.s formulate is awesome!
is working on a reply...