authentication_edit_form

Table of contents

Create form

The authentication_edit_form tag renders a form that allows the visitor logged in as a certain Authentication Type to edit his data, like his email or password.

The authentication_edit_form tag takes the plural name of an authentication type as input.

It is also possible to give extra arguments as a key, value pair. These arguments are transformed into html attributes on the generated form html tag.

The authentication_edit_form tag requires that the authentication_field tag is called inside of it for each of the inputs:

  • email

  • current_password

  • password

  • confirm_password

Accepts a parameter error_msg to use a custom message when editing the user does not work, for example when the wrong credentials are used. Message is returned in request.flash object.

Example:
{% authentication_edit_form "dealers", error_msg: "custom error message" %}
    {% authentication_field "email", class: "form-field" %}
    {% authentication_field "current_password", class: "form-field" %}
    {% authentication_field "password", class: "form-field" %}
    {% authentication_field "confirm_password", class: "form-field" %}
    <input type="submit" value="Save">
{% endauthentication_edit_form %}

Note: Do not forget to display the output of request.flash, since that contains potential error messages.

Reconfirmation email

When this form created by this tag is submitted successfully, and the email field has changed, an email will be sent to the submitted email address. It is possible to provide a custom mail template for this in a theme file located at the following path:

/mails/authentication/[authentication_type_plural_name]/reconfirm_email.plate

In this file you have access to the following variables:

  • [authentication_type_single_name], e.g. dealer: The authentication object that was updated through the form. This would return it’s email, for example: dealer.email.

  • confirm_url: The url that the user can use to her new email address.

Note: It is required that the confirm_url variable is used in the template, otherwise the user will never be able to confirm their new email.

submitted_form_fields object

Inside the 'authentication_edit_form' block, you have access to the submitted_form_fields object. This is a liquid object, representing all the fields that were submitted. This allows you to keep your form fields filled when a validation error occurred.

For example, you can use this object when rendering a form field, as follows:

{% authentication_edit_form ... %}
    {{ 'last_name' | authentication_form_input_name | html_input: "text", value: submitted_form_fields.last_name }}
{% endauthentication_edit_form %}
By setting the value of the input field to the value in the submitted_form_fields object, this input field will retain its value when the form is rendered again after a validation error on submitting the form.


JSON endpoint

Also accepts parameter output_as, which currently only accepts "json" as value. If this parameter is set, no html is returned, but everything needed for the payload in authentication endpoints is returned in JSON format. With this you can call the following endpoint in order to edit the authentication object through a JSON request:

PUT /:authentication_type_name/edit
Accept: application/json

{
    "id": :authentication_object_id,
    "authentication_object": {
        "email": "test@test.nl",
        "password": "newPa55word",
        "confirm_password": "newPa55word",
        "current_password": "currentPa55word",
        ... # JSON output from tag
    }
}

Need help?

Do you have any question which is not answered in this knowledge base? Contact us. We are here to help you.