Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-04T23:32:52.440Z
Answers.LastActivityDate: 2019-02-04T23:32:52.440Z
Answers.UserDisplayName: Roi Agneta
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-06T17:38:17.430Z
Answers.LastActivityDate: 2019-02-06T17:38:17.430Z
Answers.UserDisplayName: Jon Weedin
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-07T18:45:46.577Z
Answers.LastActivityDate: 2019-02-07T18:45:46.577Z
Answers.UserDisplayName: Christopher Dowson
Body: <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>
  
Tags: <craft3><matrix><entry-form>
Title: Matrix fields in an entry form
ThreadText: # 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:
  
  ```
  <input type="hidden" name="fields[traveller][new1][type]" value="travellerDetails">
  <input type="hidden" name="fields[traveller][new1][enabled]" value="1">
  
  ```
  
  Then, for each field within the Matrix block:
  
  ```
  <input type="text" name="fields[traveller][new1][fields][travellerTitle]" value="">
  
  ```
  
  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.
  
  
  ---
  
  