<p>Your Code has two errors:
1.  was missing.
2. The way you were fetching options was wrong.</p>

<p>Here is the correct code:</p>

<pre><code>&lt;input type="hidden" name="fields[emergencyContact]" value=""&gt;
&lt;input type="hidden" name="fields[emergencyContact][new1][type]" value="contact"&gt;
&lt;input type="hidden" name="fields[emergencyContact][new1][enabled]" value="1"&gt;
&lt;div class="grid-x grid-padding-x"&gt;
    &lt;fieldset class="cell small-3"&gt;
        &lt;label for="contactName"&gt;Name&lt;/label&gt;&lt;input type="text" name="fields[emergencyContact][new1][fields][contactName]"&gt;
    &lt;/fieldset&gt;
    &lt;fieldset class="cell small-3"&gt;
        &lt;label for="contactRelationship"&gt;Relationship&lt;/label&gt;
        {% set matrixField = craft.fields.getFieldByHandle('emergencyContact') %}
        {% set blockTypes = matrixField.getFieldType.getSettings.getBlockTypes %}
            {% for blockType in blockTypes %}
                {% if blockType.handle == "contact" %}
                     {% for field in blockType.getFields() %}
                       {% if field.handle == "contactRelationship" %}
                          &lt;select&gt;
                          {% for option in field.settings.options %}
                             &lt;option value="{{ option.value }}"&gt;{{ option.label }}&lt;/option&gt;
                           {% endfor %}
                           &lt;/select&gt;
                        {% endif %}
                      {% endfor %}
                 {% endif %}
              {% endfor %}
    &lt;/fieldset&gt;
    &lt;fieldset class="cell small-3"&gt;
        &lt;label for="contactPhone"&gt;Phone&lt;/label&gt;&lt;input type="text" name="fields[emergencyContact][new1][fields][contactPhone]"&gt;
    &lt;/fieldset&gt;
    &lt;fieldset class="cell small-3"&gt;
        &lt;label for="contactEmail"&gt;Email&lt;/label&gt;&lt;input type="email" name="fields[emergencyContact][new1][fields][contactEmail]"&gt;
    &lt;/fieldset&gt;
</code></pre>

<p>I hope it helps you.</p>

CC BY-SA 3.0
2017-11-28T15:52:14.203Z
Thank you.  I had finally come up with a working solution similar to what you presented, but ended up using yours instead. Much appreciated!
Todd
CC BY-SA 3.0
2017-11-28T12:54:00.520Z
2017-11-28T12:54:00.520Z
hashtagerrors
<p>I don't think I have a <em>specific</em> answer, but I can point you to a few posts that I think will help get you rolling. How are you creating a new row for your matrix field? </p>

<ul>
<li><a href="https://craftcms.stackexchange.com/questions/1318/how-to-get-matrix-editor-into-frontend">Get a matrix editor into front-end</a></li>
<li><a href="https://craftcms.stackexchange.com/questions/12602/managing-frontend-js-for-matrix-fields">Managing Front-end Matrix/js</a></li>
<li><a href="https://craftcms.stackexchange.com/questions/14107/how-can-i-repopulate-a-matrix-field-on-a-front-end-form">Repopulating after validation
error</a></li>
</ul>

CC BY-SA 3.0
2017-11-28T00:01:41.280Z
Right now, there are blank fields on the page where the new row would get entered.  I haven't done any additional JS/jQuery until I can get everything else working.
Todd
CC BY-SA 3.0
2017-11-27T15:29:44.267Z
2017-11-27T15:29:44.267Z
Damon
<p>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:</p>

<ul>
<li>Name (Plain Text - handle: contactName)</li>
<li>Relationship (Dropdown - handle: contactRelationship)</li>
<li>Phone (Input Mask - handle: contactPhone)</li>
<li>Email (Plain Text - handle: contactEmail)</li>
</ul>

<p>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.</p>

<p>Below is my code.  I've tried several different things, most of which gave me an error.  This is my latest attempt.</p>

<pre><code>&lt;input type="hidden" name="fields[emergencyContact][new1][type]" value="contact"&gt;
&lt;input type="hidden" name="fields[emergencyContact][new1][enabled]" value="1"&gt;
&lt;div class="grid-x grid-padding-x"&gt;
    &lt;fieldset class="cell small-3"&gt;
        &lt;label for="contactName"&gt;Name&lt;/label&gt;&lt;input type="text" name="fields[emergencyContact][new1][fields][contactName]"&gt;
    &lt;/fieldset&gt;
    &lt;fieldset class="cell small-3"&gt;
        &lt;label for="contactRelationship"&gt;Relationship&lt;/label&gt;
        &lt;select name="fields[emergencyContact][new1][fields][contactRelationship]"&gt;
        {% for option in contactRelationship.options %}
            &lt;option value="{{ option.value }}"&gt;{{ option.label }}&lt;/option&gt;
        {% endfor %}
        &lt;/select&gt;
    &lt;/fieldset&gt;
    &lt;fieldset class="cell small-3"&gt;
        &lt;label for="contactPhone"&gt;Phone&lt;/label&gt;&lt;input type="text" name="fields[emergencyContact][new1][fields][contactPhone]"&gt;
    &lt;/fieldset&gt;
    &lt;fieldset class="cell small-3"&gt;
        &lt;label for="contactEmail"&gt;Email&lt;/label&gt;&lt;input type="email" name="fields[emergencyContact][new1][fields][contactEmail]"&gt;
    &lt;/fieldset&gt;
&lt;/div&gt;
</code></pre>

<p>Anyone able to help me get this resolved?</p>

CC BY-SA 3.0
2017-11-27T15:37:24.003Z
Maybe you could tell us what happens with your current code. Does craft not save the `contactRelationship` field but the rest? Do you receive any errors or does it store the wrong value? Does it store nothing at all? Is `contactRelationship` the field with the correct `options` attribute or do you have issues with rendering the dropdown in the first place?
Robin Schambach
CC BY-SA 3.0
2017-11-27T17:02:03.070Z
With the above code, I get an error that "Variable "contactRelationship" does not exist."
Todd
CC BY-SA 3.0
2017-11-27T17:08:11.813Z
During the render process? Of course because the variable does not seem to be defined. You have to get the field by id or handle something like `set 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
CC BY-SA 3.0
2017-11-27T23:57:45.343Z
So now I'm using this - {% set dropdownField = craft.fields.getFieldByHandle('contactRelationship') %}
{% for option in dropdownField.settings.options %}
 <option value="{{ option.value }}">{{ option.label }}</option>
{% endfor %} and I get an error message - "Impossible to access an attribute ("settings") on a null variable."
Todd
CC BY-SA 3.0
2017-11-28T13:17:19.433Z
Like I said you can't get the field by handle inside a matrix element and you have to fetch the dropDown field, not your matrix field `contactRelationship = craft.fields.getFieldById(yourDateTimeFieldId)` is what you want
Robin Schambach
<matrix><frontend><drop-down>
Front End Form with Dropdown in Matrix - Adding New
# Front End Form with Dropdown in Matrix - Adding New

(Asked by: username_0 on 2017-11-27)

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.



    
        Name
    
    
        Relationship
        
        {% for option in contactRelationship.options %}
            {{ option.label }}
        {% endfor %}
        
    
    
        Phone
    
    
        Email
    


Anyone able to help me get this resolved?

**Tags:** matrix, frontend, drop-down

> **Comments:**
> **username_1**: Maybe you could tell us what happens with your current code. Does craft not save the `contactRelationship` field but the rest? Do you receive any errors or does it store the wrong value? Does it store nothing at all? Is `contactRelationship` the field with the correct `options` attribute or do you have issues with rendering the dropdown in the first place?  
> **username_0**: With the above code, I get an error that "Variable "contactRelationship" does not exist."  
> **username_1**: During the render process? Of course because the variable does not seem to be defined. You have to get the field by id or handle something like `set 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  
> **username_0**: So now I'm using this - {% set dropdownField = craft.fields.getFieldByHandle('contactRelationship') %} {% for option in dropdownField.settings.options %}  <option value="{{ option.value }}">{{ option.label }}</option> {% endfor %} and I get an error message - "Impossible to access an attribute ("settings") on a null variable."  
> **username_1**: Like I said you can't get the field by handle inside a matrix element and you have to fetch the dropDown field, not your matrix field `contactRelationship = craft.fields.getFieldById(yourDateTimeFieldId)` is what you want  

---

## 2 answers

### Answer by username_2 on 2017-11-28. Score: 3 | Accepted answer

Your Code has two errors:
1.  was missing.
2. The way you were fetching options was wrong.
Here is the correct code:




    
        Name
    
    
        Relationship
        {% set matrixField = craft.fields.getFieldByHandle('emergencyContact') %}
        {% set blockTypes = matrixField.getFieldType.getSettings.getBlockTypes %}
            {% for blockType in blockTypes %}
                {% if blockType.handle == "contact" %}
                     {% for field in blockType.getFields() %}
                       {% if field.handle == "contactRelationship" %}
                          
                          {% for option in field.settings.options %}
                             {{ option.label }}
                           {% endfor %}
                           
                        {% endif %}
                      {% endfor %}
                 {% endif %}
              {% endfor %}
    
    
        Phone
    
    
        Email
    

I hope it helps you.

> **Comments:**
> **username_0**: Thank you.  I had finally come up with a working solution similar to what you presented, but ended up using yours instead. Much appreciated!  

---

### Answer by username_3 on 2017-11-27. Score: 1

I don't think I have a *specific* answer, but I can point you to a few posts that I think will help get you rolling. How are you creating a new row for your matrix field?

* [Get a matrix editor into front-end](https://craftcms.stackexchange.com/questions/1318/how-to-get-matrix-editor-into-frontend)
* [Managing Front-end Matrix/js](https://craftcms.stackexchange.com/questions/12602/managing-frontend-js-for-matrix-fields)
* [Repopulating after validation
  error](https://craftcms.stackexchange.com/questions/14107/how-can-i-repopulate-a-matrix-field-on-a-front-end-form)

> **Comments:**
> **username_0**: Right now, there are blank fields on the page where the new row would get entered.  I haven't done any additional JS/jQuery until I can get everything else working.  

---

