What is GoodNewsUpdateProfile?

GoodNewsUpdateProfile is a Snippet that allows Subscribers to update their subscription profile (e.g. mailing groups, categories, email address) in the front-end of your website.

A susbcriber will never need to know his MODX user credentials! Updating the Subscribers profile or unsubscription will be handled through a secure link from within a newsletter with an aditional and unique secure ID parameter.

How to use the Snippet

You need to place the GoodNewsUpdateProfile Snippet in the Resource where your profile update form resides.

Default properties for the Snippet

The GoodNewsUpdateProfile Snippet implements the following properties (many of them are equivalent to the properties you can find in the well known UpdateProfile Snippet of the Login add-on):

Property Description Default
errTpl Chunk for error output. <span class="error">[[+error]]</span>
useExtended Whether or not to set any extra fields in the form to the users extended field. 0 = false
excludeExtended A comma-separated list of fields to exclude from setting as extended fields.
emailField The name of the field to use for the Subscribers's email address. email
preHooks A comma-separated list of 'hooks' (Snippets), that will be executed before the user profile is updated but after validation.
postHooks A comma-separated list of 'hooks' (Snippets), that will be executed after the user profile is updated.
sendUnauthorizedPage Whether or not to redirect a Subscriber to the unauthorized page if his authentication is not verified. 0 = false
reloadOnSuccess If true, page will redirect to itself to prevent double-postbacks. Otherwise it will set a success placeholder. 1 = true
submitVar The name of the form submit button that triggers the submission. goodnews-updateprofile-btn
successKey The name of the key submitted as url param in case of success. updsuccess
successMsg If page redirects to itself, this message will be set to a placeholder.
validate A comma-separated list of fields to validate.
grpFieldsetTpl Chunk name for GoodNews group fieldset. sample.GoodNewsGrpFieldsetTpl
grpFieldTpl Chunk name for GoodNews group checkbox element. sample.GoodNewsGrpFieldTpl
grpNameTpl Chunk name for GoodNews group name element. sample.GoodNewsGrpNameTpl
grpFieldHiddenTpl Chunk name for GoodNews group input hidden element. sample.GoodNewsGrpFieldHiddenTpl
catFieldTpl Chunk name for GoodNews category checkbox element. sample.GoodNewsCatFieldTpl
catFieldHiddenTpl Chunk name for GoodNews category input hidden element. sample.GoodNewsCatFieldHiddenTpl
groupsOnly Whether or not the output should only contain GoodNews groups. 0 = false
includeGroups Comma separated list of GoodNews group ids to be used for output. 0 = use all groups
defaultGroups Comma separated list of GoodNews group ids which should be preselected as hidden fields. 0 = none
defaultCategories Comma separated list of GoodNews category ids which should be preselected as hidden fields. 0 = none
sort Field to sort by for GoodNews groups/categories. name
dir Sort direction for GoodNews groups/categories. ASC
grpCatPlaceholder The placeholder to set the generated GoodNews groups/categories tree to. grpcatfieldsets
placeholderPrefix The prefix to use for all placeholders set by this Snippet.

Field Validators

Field Validators in GoodNewsUpdateProfile follow the same syntax as the validators of the FormIt add-on. You can use the methods described there to use them in your GoodNewsUpdateProfile setup.

An example GoodNewsUpdateProfile Snippet call would look like this:

[[!GoodNewsUpdateProfile?
    &validate=`
        email:email:required,
        nospam:blank`
    &defaultGroups=`1`
]]

You can read about the handling and output of GoodNews groups and categories in the GoodNewsSubscription Snippet documentation.

Sample Form for Updating a Subscription Profile

For a sample and universal form to update GoodNews profiles, please have a look at the code below. This code is conceived to automatically handle hidden and/or selectable GoodNews groups and categories output.

<div class="main">
    <h2>Edit your mailing profile</h2>
    <p>
        You can edit your mailing profile here. Please check/uncheck the newsletter topics you are interested in.
    </p>
    <form id="profileform" class="gon-form" action="[[~[[*id]]]]?sid=[[!+sid]]" method="post">
        <input type="hidden" name="nospam" value="[[!+nospam]]">
        [[!+update_success:is=`1`:then=`
            <p class="successMsg">Your mailing profile was updated successfully!</p>
        `]]
        [[!+error.message:notempty=`
            <p class="errorMsg">[[!+error.message]]</p>
        `]]
        <fieldset>
            <legend>Personal Data</legend>
            <p class="fieldbg[[!+error.email:notempty=` fielderror`]]">
                <label for="email">
                    E-Mail Address
                    [[!+error.email]]
                </label>
                <input type="email" name="email" id="email" value="[[!+email]]" placeholder="Please enter your e-mail address" required>
            </p>
            <p class="fieldbg[[!+error.fullname:notempty=` fielderror`]]">
                <label for="fullname">
                    First and Last Name (optional)
                    [[!+error.fullname]]
                </label>
                <input type="text" name="fullname" id="fullname" value="[[!+fullname]]" placeholder="Please enter your first and last name">
            </p>
        </fieldset>
        [[!+fields_hidden:is=`1`:then=`[[!+grpcatfieldsets]]`:else=`
        <fieldset>
            <legend>Newsletter Topics</legend>
            <p class="fieldbg">
                <label class="singlelabel">
                    Please choose the newsletter topics you are interested in.
                    [[!+error.gongroups]]
                    [[!+error.goncategories]]
                </label>
                <input type="hidden" name="gongroups[]" value="">
                <input type="hidden" name="goncategories[]" value="">
            </p>
            [[!+grpcatfieldsets]]
        </fieldset>
        `]]
        <p>
            <button type="submit" role="button" name="goodnews-updateprofile-btn" value="Update" class="button green">Update profile</button>
        </p>
    </form>
</div>