I've got a Matrix field called Emergency Contacts (handle: emergencyContact) that I'm setting up so that users can add/update on the front end. It has one block type - contact - with 4 fields:
- Name (Plain Text - handle: contactName)
- Relationship (Dropdown - handle: contactRelationship)
- Phone (Input Mask - handle: contactPhone)
- Email (Plain Text - handle: contactEmail)
I have everything displaying correct when I show existing information. However, when they go to enter a new emergency contact, I can't figure out the right syntax to populate the dropdown menu to populate with the options for them to select.
Below is my code. I've tried several different things, most of which gave me an error. This is my latest attempt.
<input type="hidden" name="fields[emergencyContact][new1][type]" value="contact">
<input type="hidden" name="fields[emergencyContact][new1][enabled]" value="1">
<div class="grid-x grid-padding-x">
<fieldset class="cell small-3">
<label for="contactName">Name</label><input type="text" name="fields[emergencyContact][new1][fields][contactName]">
</fieldset>
<fieldset class="cell small-3">
<label for="contactRelationship">Relationship</label>
<select name="fields[emergencyContact][new1][fields][contactRelationship]">
{% for option in contactRelationship.options %}
<option value="{{ option.value }}">{{ option.label }}</option>
{% endfor %}
</select>
</fieldset>
<fieldset class="cell small-3">
<label for="contactPhone">Phone</label><input type="text" name="fields[emergencyContact][new1][fields][contactPhone]">
</fieldset>
<fieldset class="cell small-3">
<label for="contactEmail">Email</label><input type="email" name="fields[emergencyContact][new1][fields][contactEmail]">
</fieldset>
</div>
Anyone able to help me get this resolved?
contactRelationship
field but the rest? Do you receive any errors or does it store the wrong value? Does it store nothing at all? IscontactRelationship
the field with the correctoptions
attribute or do you have issues with rendering the dropdown in the first place? – Robin Schambach Nov 27 '17 at 15:37set contactRelationship = craft.field.getFieldById(id)
I'm at my smartphone currently so maybe the syntax is wrong but it should be something like that. Edit stupid me since it is in a matrix you can get the field only by id – Robin Schambach Nov 27 '17 at 17:08contactRelationship = craft.fields.getFieldById(yourDateTimeFieldId)
is what you want – Robin Schambach Nov 28 '17 at 13:17