8

I have used the following code to allow our users to update their own profile. Everything works fine apart from not being able to update existing Matrix entries.

New Matrix field entries work fine. Can anyone spot the mistake I've made?

          <form method="post" accept-charset="UTF-8">
          {{ getCsrfInput() }}
          <input type="hidden" name="action" value="users/saveUser">
          <input type="hidden" name="redirect" value="/account/profile">
          <input type="hidden" name="userId" value="{{ currentUser.id }}">

          <label for="firstName">First Name</label>
          <input type="text" id="firstName" name="firstName" value="{{ currentUser.firstName }}">

          <label for="lastName">Last Name</label>
          <input type="text" id="lastName" name="lastName" value="{{ currentUser.lastName }}">

          <label for="telephone">Telephone</label>
          <input type="text" id="telephone" name="fields[telephone]" value="{{ currentUser.telephone }}">

          <h3>Additional Contacts</h3>

          <input type="hidden" name="fields[alternativeContacts]" value="">

          {% for block in currentUser.alternativeContacts.type('contact') %}
          <div class="row">
            <input type="hidden" name="fields[alternativeContacts][{{ block.id }}][type]" value="contact">
            <input type="hidden" name="fields[alternativeContacts][{{ block.id }}][enabled]" value="1">

            <input type="text" name="fields[alternativeContacts][{{ block.id }}][fields][firstName]" value="{{ block.firstName }}">
            <input type="text" name="fields[alternativeContacts][{{ block.id }}][fields][lastName]" value="{{ block.lastName }}">
            <input type="text" name="fields[alternativeContacts][{{ block.id }}][fields][telephone]" value="{{ block.telephone }}">
            <input type="email" name="fields[alternativeContacts][{{ block.id }}][fields][email]" value="{{ block.email }}">

            <button class="btn btn-xs btn-danger" data-action="delete-contact"><i class="fa fa-times"></i></button>
          </div>
          {% endfor %}

          <div class="row">
            <h6>New Contact</h6>

            <input type="hidden" name="fields[alternativeContacts][new1][type]" value="contact">
            <input type="hidden" name="fields[alternativeContacts][new1][enabled]" value="1">

            <input type="text" name="fields[alternativeContacts][new1][fields][firstName]">
            <input type="text" name="fields[alternativeContacts][new1][fields][lastName]">
            <input type="text" name="fields[alternativeContacts][new1][fields][telephone]">
            <input type="email" name="fields[alternativeContacts][new1][fields][email]">
          </div>

          <input type="submit" value="Save Profile">
      </form>
| improve this question | | | | |
  • 1
    Weirdly, if I remove the new entry field it works fine. Perhaps I'm hitting some validation issues and nothing's updating... hmmmm – GlennJ Jan 10 '15 at 10:43
2

Turns out it was a validation issue, it works fine when you make the new contact's first+last name mandatory.

| improve this answer | | | | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.