im using the same form on events pages - name, email, telephone, enquiry.
ideally is there a way of passing the current page url as a hidden field? or adding a field with event but dynamically input the field with @currentPage.title so when its submitted the client knows what page the form was submitted.
Custom Hidden Field Type. You can create a custom hidden field type. You can read about creating custom field types here. You could then have some JavaScript look for that field and then set the value to the current URL. Right now, you'll have to find the field by field ID (i.e., the funky GUID). If you like, I can modify the built-in Responsive Bootstrap Angular template to output a data attribute containing the field alias (e.g., so you can find a field with an alias of "currentUrl"). Alternatively, you could make your custom hidden field type be used specifically for the URL, in which case you could populate the value on the server side when the form is rendered.
Payload. In the Responsive.Bootstrap.Angular.cshtml file, there is an anonymous object that gets created and serialized to JSON. Part of that object is an associative array called "payload". Currently, that associative array contains only the form ID (see screenshot below). You could add the current URL to this payload as well, and Formulate will send it to the server when submitting the AJAX request. However, I forget if Formulate will include those payload fields in the default email handler that sends out emails when forms are submitted. If not, let me know and we can tinker with that to get something working. If it does include it in the email, it will probably refer to it as "Unknown Field" (again, we can discuss options if you prefer the name in the email to be more specific).
// Convert to a JSON string that can be consumed by Angular.
var angularModel = Json.Encode(new
{
data = new
{
// The name of the form can be use for analytics.
name = Model.FormDefinition.Name,
// The form alias can be used for custom styles.
alias = Model.FormDefinition.Alias,
// The random ID can be used to uniquely identify the form on the page.
// Note that this random ID is regenerated on each page render.
randomId = Guid.NewGuid().ToString("N"),
// The fields in this form.
fields = fieldsData,
// The rows that define the form layout.
rows = rowsData,
payload = new
{
FormId = Model.FormDefinition.FormId.ToString("N"),
CurrentUrl = Request.Url
},
url = "/umbraco/formulate/submissions/submit"
}
});
Pull Request. Submit a pull request to Formulate to add the "Current URL" as a first-class citizen so that it is sent with all submissions. This seems like a good thing to include in all requests. The page name could also be included (might even be good to include a full breadcrumb of all ancestor page names too).
Another option would be to combine the above hack with a pull request. The pull request would implement a map between GUID's to field names (perhaps in a config file). That way, if Formulate sees the key "A9B9B38006D64E57B5FEB7E23B804D4E" (as in the example above), you could have it be mapped to a nicer name in the email (e.g., "Current URL").
I'm also open to other alternatives if you have any ideas other than those I've so far presented.
hidden fields - current url
Hi Nicholas
hope this makes sense.
im using the same form on events pages - name, email, telephone, enquiry.
ideally is there a way of passing the current page url as a hidden field? or adding a field with event but dynamically input the field with @currentPage.title so when its submitted the client knows what page the form was submitted.
i have updated to the latest version.
Regards,
Ian
There are a few ways I can think of doing this:
Responsive.Bootstrap.Angular.cshtml
file, there is an anonymous object that gets created and serialized to JSON. Part of that object is an associative array called "payload". Currently, that associative array contains only the form ID (see screenshot below). You could add the current URL to this payload as well, and Formulate will send it to the server when submitting the AJAX request. However, I forget if Formulate will include those payload fields in the default email handler that sends out emails when forms are submitted. If not, let me know and we can tinker with that to get something working. If it does include it in the email, it will probably refer to it as "Unknown Field" (again, we can discuss options if you prefer the name in the email to be more specific).hi Nicholas
could you point me in the right direction of what to add in the payload?
regards.
Something like this should work:
hi Nicholas
it doesnt send the url in the email.
// Convert to a JSON string that can be consumed by Angular. var angularModel = Json.Encode(new { data = new { // The name of the form can be use for analytics. name = Model.FormDefinition.Name, // The form alias can be used for custom styles. alias = Model.FormDefinition.Alias, // The random ID can be used to uniquely identify the form on the page. // Note that this random ID is regenerated on each page render. randomId = Guid.NewGuid().ToString("N"), // The fields in this form. fields = fieldsData, // The rows that define the form layout. rows = rowsData, payload = new { FormId = Model.FormDefinition.FormId.ToString("N"), CurrentUrl = Request.Url }, url = "/umbraco/formulate/submissions/submit" } });
}
I confirmed the same just now. The problem seems to be this line: https://github.com/rhythmagency/formulate/blob/887b3be63c51cc0bf500eb922a686a63ad6e304a/src/formulate.api/Controllers/SubmissionsController.cs#L59
It is only allowing values that were submitted with a GUID key. Not that I recommend it, but here's a hack that worked for me just now:
In other words, I used a GUID as the key. And I confirmed that the email does actually say "Unknown Field" (followed by the currect URL).
If you don't like that hack (I know I don't), here are some other options:
Another option would be to combine the above hack with a pull request. The pull request would implement a map between GUID's to field names (perhaps in a config file). That way, if Formulate sees the key "A9B9B38006D64E57B5FEB7E23B804D4E" (as in the example above), you could have it be mapped to a nicer name in the email (e.g., "Current URL").
I'm also open to other alternatives if you have any ideas other than those I've so far presented.
hi Nicholas
thanks for this.
yes the unknown field isnt great but i have added it for now.
could we try the pull request?
i have added a "events" form field to one of the forms, ideally id like to pass the event title and possibly other details to that.
plus the url.
cheers
Sure thing. To ensure your pull request is accepted, first outline the changes you plan to make in a new issue here: https://github.com/rhythmagency/formulate/issues
Let me know if you need any pointers on how to contribute to the Formulate core codebase.
FYI, the URL and page name can now be included in emails in the latest version of Formulate (0.3.7).
is working on a reply...