A note on Elements
Craft allows plugins to create custom Element Types. Elements have the option to support URIs, but it is not required. Out of the box, Craft currently has 7 Element Types and only two of them (Entries, Categories) support URIs. Here's a good overview of the default Elements.
Sprout Form Element Types and URIs
Sprout Forms adds two new Elements to Craft. The SproutForms_Form
Element and the SproutForms_Entry
Element both which do not support URIs simply because we didn't feel there was a strong use case for them to be implemented for most form submission scenarios.
While it may not make sense to support URIs for all SproutForm_Entry
Elements out of the box, you can still create a way for those Elements to be linked to in your templates, you will just have to do it manually.
How to manually create URIs for Sprout Form Entry Elements
To customize Craft to handle custom URLs for an Element that doesn't support URLs (of even for an Element that supports that that you need to do something fancy with), here is a rough example of the steps needed.
Loop through your Elements and output the URL you wish them to have to link to your Entries:
/submissions/{{ formEntry.id }}
You will then need to setup a route to tell Craft which template it should load when it encounters a URL like that. You can create a route in the CP or in the craft/config/routes.php
file. This route tells Craft to load the submission/_entry.html
template each time a URL matches submission/ANYTHING
:
return array(
'submissions/(?P<formEntryId>.*)' => 'submissions/_entry'
);
In your submissions/_entry
template, you will need to use the ID information in the URL to query for the Form Entry that you wish to display:
{% set entry = craft.sproutForms.getEntryById(formEntryId) %}
In the above example, we're able to use the formEntryId
variable because we setup our route to assign the second segment of the URL to the value formEntryId
. If you setup your route in the control panel, you may need to grab the ID using getSegment
:
{% set formEntryId = craft.request.getSegment(2) %}
{% set entry = craft.sproutForms.getEntryById(formEntryId) %}