1

I'm using the following modified version of the user registration form for the purpose of a user updating their details.

<form method="post" accept-charset="UTF-8" enctype="multipart/form-data" class="form form--full">

    {{ getCsrfInput() }}

    <input type="hidden" name="action" value="users/saveUser">
    <input type="hidden" name="redirect" value="profile">
    <input type="hidden" name="userId" value="{{ currentUser.id }}">

    <fieldset>
        <legend class="visually-hidden">Personal details</legend>
        {{ account is defined ? _self.errorList(account.getAllErrors()) : 'not' }}

        <div class="form__group">
            <label class="form__pullLabel" for="firstName">First name<span class="required">*</span></label>
            <div class="form__input">
                <input id="firstName" type="text" name="firstName" value="{{ currentUser.firstName }}" placeholder="First name" required="required" aria-required="true" autofocus="autofocus">
            </div>
        </div>

        <div class="form__group">
            <label class="form__pullLabel" for="lastName">Last name<span class="required">*</span></label>
            <div class="form__input">
                <input id="lastName" type="text" name="lastName" value="{{ currentUser.lastName }}" placeholder="Surname" required="required" aria-required="true">
            </div>
        </div>

        <div class="form__group">
            <label class="form__pullLabel" for="email">Email<span class="required">*</span></label>
            <div class="form__input">
                <input id="email" type="email" name="email" value="{{ currentUser.email }}" placeholder="Email address" required="required" aria-required="true" disabled="disabled">
            </div>
        </div>

        <div class="form__group">
            <label class="form__pullLabel" for="mobileNumber">Phone / Mobile number</label>
            <div class="form__input">
                <input id="mobileNumber" type="tel" name="fields[mobileNumber]" placeholder="Phone number" value="{{ currentUser.mobileNumber }}" aria-required="false">
            </div>
        </div>

        <div class="form__group">
            <label class="form__pullLabel" for="company">Company / Organisation<span class="required">*</span></label>
            <div class="form__input">
                <input id="company" type="text" name="fields[company]" value="{{ currentUser.company }}" limit="150" placeholder="Company" required="required" aria-required="true">
            </div>
        </div>

        <div class="form__group">
            <label class="form__pullLabel" for="position">Position</label>
            <div class="form__input">
                <input id="position" type="text" name="fields[position]" value="{{ currentUser.position }}" placeholder="Position" aria-required="false">
            </div>
        </div>

        <div class="form__group">
            <label class="form__pullLabel" for="profilePhoto">Profile photo</label>
            <div class="form__input imageSelect">
                {% if currentUser.photoUrl %}
                    <img src="{{ currentUser.photoUrl }}" id="userPhoto" /><input type="hidden" name="deleteUserPhoto" id="deleteUserPhotoInput" value="">{% else %}<img src="{{ url(siteSettings.defaultUserImage.first.getUrl()) }}" width="100" alt="no profile image" />{% endif %}<input id="profilePhoto" type="file" accept="image/*" capture="camera" name="userPhoto" value="{{ (currentUser.photoUrl ? 'Change Photo' : 'Upload') }}">
                {% if currentUser.photoUrl %}
                    <a id="deleteUserPhotoAction" class="button button--reverse ut-marginTop">Delete</a>
                {% endif %}
            </div>
        </div>

        <button class="spinnerHolder button button--full" type="submit">Save details</button>
   </fieldset>

</form>

This updates, however I can't seem to get any errors for empty fields

Does anything look off? If not, can you perhaps give a push in the right direction as to why it may not be working?

Thanks

  • 1
    _self.errorList(account.getAllErrors()) - have you actually defined a macro called errorList? Your example code doesn't show it. – Brad Bell Oct 30 '15 at 17:34
  • Sorry for not including. Yes I have, above the content as in the documentation example – user4041 Oct 31 '15 at 19:40
2

Ok, so the problem wasn't what I initially expected

After a bit of searching, I found out that the default first name and last name fields are not required by default and there's no way to make them required. As a result, validation wasn't failing; hence no account object to get errors from

My solution was to just create two extra custom fields User First Name and User Last Name. Not ideal, but solves the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy