Answers.Body: <p>Turns out it was a validation issue, it works fine when you make the new contact's first+last name mandatory.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-10T10:50:46.210Z
Answers.LastActivityDate: 2015-01-10T10:50:46.210Z
Answers.UserDisplayName: GlennJ
Body: <p>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.</p>
  
  <p>New Matrix field entries work fine. Can anyone spot the mistake I've made?</p>
  
  <pre><code>          &lt;form method="post" accept-charset="UTF-8"&gt;
            {{ getCsrfInput() }}
            &lt;input type="hidden" name="action" value="users/saveUser"&gt;
            &lt;input type="hidden" name="redirect" value="/account/profile"&gt;
            &lt;input type="hidden" name="userId" value="{{ currentUser.id }}"&gt;
  
            &lt;label for="firstName"&gt;First Name&lt;/label&gt;
            &lt;input type="text" id="firstName" name="firstName" value="{{ currentUser.firstName }}"&gt;
  
            &lt;label for="lastName"&gt;Last Name&lt;/label&gt;
            &lt;input type="text" id="lastName" name="lastName" value="{{ currentUser.lastName }}"&gt;
  
            &lt;label for="telephone"&gt;Telephone&lt;/label&gt;
            &lt;input type="text" id="telephone" name="fields[telephone]" value="{{ currentUser.telephone }}"&gt;
  
            &lt;h3&gt;Additional Contacts&lt;/h3&gt;
  
            &lt;input type="hidden" name="fields[alternativeContacts]" value=""&gt;
  
            {% for block in currentUser.alternativeContacts.type('contact') %}
            &lt;div class="row"&gt;
              &lt;input type="hidden" name="fields[alternativeContacts][{{ block.id }}][type]" value="contact"&gt;
              &lt;input type="hidden" name="fields[alternativeContacts][{{ block.id }}][enabled]" value="1"&gt;
  
              &lt;input type="text" name="fields[alternativeContacts][{{ block.id }}][fields][firstName]" value="{{ block.firstName }}"&gt;
              &lt;input type="text" name="fields[alternativeContacts][{{ block.id }}][fields][lastName]" value="{{ block.lastName }}"&gt;
              &lt;input type="text" name="fields[alternativeContacts][{{ block.id }}][fields][telephone]" value="{{ block.telephone }}"&gt;
              &lt;input type="email" name="fields[alternativeContacts][{{ block.id }}][fields][email]" value="{{ block.email }}"&gt;
  
              &lt;button class="btn btn-xs btn-danger" data-action="delete-contact"&gt;&lt;i class="fa fa-times"&gt;&lt;/i&gt;&lt;/button&gt;
            &lt;/div&gt;
            {% endfor %}
  
            &lt;div class="row"&gt;
              &lt;h6&gt;New Contact&lt;/h6&gt;
  
              &lt;input type="hidden" name="fields[alternativeContacts][new1][type]" value="contact"&gt;
              &lt;input type="hidden" name="fields[alternativeContacts][new1][enabled]" value="1"&gt;
  
              &lt;input type="text" name="fields[alternativeContacts][new1][fields][firstName]"&gt;
              &lt;input type="text" name="fields[alternativeContacts][new1][fields][lastName]"&gt;
              &lt;input type="text" name="fields[alternativeContacts][new1][fields][telephone]"&gt;
              &lt;input type="email" name="fields[alternativeContacts][new1][fields][email]"&gt;
            &lt;/div&gt;
  
            &lt;input type="submit" value="Save Profile"&gt;
        &lt;/form&gt;
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-10T10:43:59.987Z
Comments.Text: Weirdly, if I remove the new entry field it works fine. Perhaps I'm hitting some validation issues and nothing's updating... hmmmm
Comments.UserDisplayName: GlennJ
Tags: <matrix><user-profile><frontend>
Title: How to update Matrix field on frontend for user profile
ThreadText: # How to update Matrix field on frontend for user profile
  
  (Asked by: username_0 on 2015-01-10)
  
  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>
  
  ```
  
  **Tags:** matrix, user-profile, frontend
  
  > **Comments:**
  > **username_0**: Weirdly, if I remove the new entry field it works fine. Perhaps I'm hitting some validation issues and nothing's updating... hmmmm  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-01-10. Score: 2
  
  Turns out it was a validation issue, it works fine when you make the new contact's first+last name mandatory.
  
  
  ---
  
  