2

Referencing https://craftcms.com/docs/3.x/matrix-fields.html#saving-matrix-fields I believe I did this correctly according to the docs and other posts here. My Matrix field is able to save edits, but when the field is empty adding a new block does NOT work.

POST data from the form submission:

enter image description here

Code:

{{ hiddenInput('fields[vendorLocations][blocks][new1][type]', 'address') }}
{{ hiddenInput('fields[vendorLocations][blocks][new1][enabled]', '1') }}
<select name="fields[vendorLocations][blocks][new1][fields][city]" required>
   <option value="">Choose One</option>
   {% for city in riCities() %}
     <option value="{{ city|title }}">{{ city|title }}</option>
   {% endfor %}
</select>

Desired CMS Result:

enter image description here

1
  • try to remove [blocks].
    – aodihis
    Sep 20, 2022 at 1:49

1 Answer 1

5

After talking to Craft Support (Thanks Oli!), the solution for Craft 3 is...

{{ hiddenInput('fields[vendorLocations][sortOrder][]', 'new:1') }}

{{ hiddenInput('fields[vendorLocations][blocks][new:1][type]', 'address') }}


<select name="fields[vendorLocations][blocks][new:1][fields][city]" required>
   <option value="">Choose One</option>
   {% for city in riCities() %}
     <option value="{{ city|title }}">{{ city|title }}</option>
   {% endfor %}
</select>

Make sure the proper entryTypeId, section etc. is defined for your form as well, this is just the specifics for the new matrix block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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