Using EditCode fields
The EditCodes are designed to provide per-record access to a Form record without using the (predictable, sequential) recordid, and without using the ownership of a record.
This is typically used to provide an easy-to-use interface for visitors to edit their preferences, without having to register, choose a password, (and then later login and remember the password). Instead, they are emailed a link to the Form where they can edit their preferences, the link containing the unique 'editcode' which silently authenticates them.
In this example we will create a Form where visitors can sign up to receive an email newsletter. When they sign up, they are emailed a link – containing the editcode – which allows them to change their preferences (which in this simple example allows them to change their email address, or choose not to receive the newsletter any more)
Add the following components to the site:
- Form, called '"Subscription"
- Section, called "Thank you" (you can set this to be Hidden in the navigation)
Make the following configuration settings to the "Subscription" Form:
Behavior Editor, Settings, Options:
- "Show Default Edit Record Form" > No
- "Allow edit of record with edit code" > Yes
- "Redirect target after record update" > "Thank you" page
Behavior Editor, Permissions, Visitor
"View Page" and "Submit Records" set to Allow
On the Form Fields tab:
Add the following fields:
- Text "Name"
- Email "Email address"
- Checkbox "Send newsletters"
- EditCode "EditCode"
On the Events tab:
- Add an email Action under "Form Record Change" and name it "Email visitor"
- (Right click on Form Record Change, and click Add Action, and enter "Email visitor" against Action Name, and select "Form record change email" from the Action Type dropdown)
- Configure the email
- (right click on the "Email visitor" node in the tree, and select Properties, then fill in the form as described)
- Set the "To" field to the Form Field – Email address (click on the To field, then select the field from the "(choose an embed option)" dropdown
- Enter your own email address in the From field. (Ensure this is valid, otherwise the email won't be able to get sent out, nor will you receive any replies or bounces.)
- Enter a subject line.
- In the message body enter any suitable welcoming text. You can embed the Name field to personalise this.
- Enter some words about unsubscribing, and then, on a new line, we will enter the URL they need to go to.
- The URL is made up by a series of embeds – it is important when entering these to avoid entering any spaces between them. The first embed is for the Form page. Rather than entering this manually, we use an embed (so that if the domain name changes later, it will still work). So start by selecting from the "(choose an embed option)" dropdown "Page link?" and in the site tree picker that appears, select the "Subscription" Form. This will place an embed code in the message body. Immediately after this (no spaces) embed "Link Param – Record ID" and then (again with no spaces) type ec= and then embed the EditCode field.
- OK out of the dialog, (and remember to click Apply at the bottom of the Event tab or you will lose your changes)
Edit Text, Record Edit View:
- In the text editor, enter any explanatory text which should appear above the Form (phrase this so that it is suitable for new people and those returning to modify their preferences), and embed all the form fields except the EditCode. Also embed a Submit button
Now, to test it. If you are still logged in, log out of the site, or use a different machine.
Browse to the Subscription page. Fill in the details as requested, with your email address. When the email arrives, click on the link. It should take you to the same form, already filled in with your details form before, which you can update. This should then send you another email.
Extending the example
This example has focussed on the use of the EditCode datatype to provide per-record access without the need for user identification by logging in.
In a real-world scenario, you would want to extend this:
- You would want to have several emails, with Conditions set so they are sent in different circumstances: for a new subscriber vs an update, and for someone who does want to receive emails vs someone who doesn't (even the latter should probably receive a one-time email with the URL, in case they change their mind)
- The "Thank You" page should get filled in with some text, explaining what will happen next
- And of course, this example does not cover the actual sending of the newsletter emails to the people who want them. (There are two ways of doing this, an integrated method where the site sends the newsletter emails, or an external method, where you export a CSV file containing the email addresses of hose who want to receive them, for use in another email program)