<p>The trick, as it were, is to define the Matrix field in your form as an array. </p>

<p>First, the Matrix entry field itself:</p>

<pre><code>&lt;input type="hidden" name="fields[traveller][new1][type]" value="travellerDetails"&gt;
&lt;input type="hidden" name="fields[traveller][new1][enabled]" value="1"&gt;
</code></pre>

<p>Then, for each field within the Matrix block:</p>

<pre><code>&lt;input type="text" name="fields[traveller][new1][fields][travellerTitle]" value=""&gt;
</code></pre>

<p>If you are going to allow for more than one Matrix field in your form, you must increment the block number, e.g. "new1" becomes "new2". You can do that with some JS.</p>

CC BY-SA 4.0
2019-02-04T23:32:52.440Z
2019-02-04T23:32:52.440Z
Roi Agneta
<p>Do you have something like <code>{{ entry.traveller.one().travellerDetails.one().travellerTitle }}</code>? Even if you limit the number of matrixes to 1, Craft still creates an array, so you need to include <code>.one()</code> after the matrix field name and matrix block name. If you use a <code>for</code> loop, you wouldn't need the <code>.one()</code>.</p>

CC BY-SA 4.0
2019-02-06T17:38:17.430Z
2019-02-06T17:38:17.430Z
Jon Weedin
<p>Thanks to everyone for their input, but I solved the problem using an alternative fieldtype. I'd have rather stuck with a native fieldtype, but deadlines are an unforgiving mistress.</p>

CC BY-SA 4.0
2019-02-07T18:45:46.577Z
2019-02-07T18:45:46.577Z
Christopher Dowson
<p>I'm attempting to get matrix fields to populate in an entry form (using the guest post plugin) and so far just can't seem to crack it. I've tried various examples, but all assume that you're just editing an existing entry, not posting a new one (that a non-cp user would never need to edit). </p>

<p>The code is so wrong there's little point posting it.</p>

<p>I'm sure if someone can point me in the right direction, I'd be able to take it from there.</p>

<p>The matrix field is called <code>traveller</code>, the block is called <code>travellerDetails</code> and the field I want to try is called <code>travellerTitle</code> (a dropdown field).</p>

<craft3><matrix><entry-form>
Matrix fields in an entry form
# Matrix fields in an entry form

(Asked by: username_0 on 2019-02-04)

I'm attempting to get matrix fields to populate in an entry form (using the guest post plugin) and so far just can't seem to crack it. I've tried various examples, but all assume that you're just editing an existing entry, not posting a new one (that a non-cp user would never need to edit).

The code is so wrong there's little point posting it.

I'm sure if someone can point me in the right direction, I'd be able to take it from there.

The matrix field is called `traveller`, the block is called `travellerDetails` and the field I want to try is called `travellerTitle` (a dropdown field).

**Tags:** craft3, matrix, entry-form

---

## 3 answers

### Answer by username_1 on 2019-02-04. Score: 5

The trick, as it were, is to define the Matrix field in your form as an array. 
First, the Matrix entry field itself:



Then, for each field within the Matrix block:


If you are going to allow for more than one Matrix field in your form, you must increment the block number, e.g. "new1" becomes "new2". You can do that with some JS.


---

### Answer by username_2 on 2019-02-06. Score: 1

Do you have something like `{{ entry.traveller.one().travellerDetails.one().travellerTitle }}`? Even if you limit the number of matrixes to 1, Craft still creates an array, so you need to include `.one()` after the matrix field name and matrix block name. If you use a `for` loop, you wouldn't need the `.one()`.


---

### Answer by username_0 on 2019-02-07. Score: 1

Thanks to everyone for their input, but I solved the problem using an alternative fieldtype. I'd have rather stuck with a native fieldtype, but deadlines are an unforgiving mistress.


---

