4

Is it possible to populate a Matrix Field, Table and Lightbox using the GuestEntries plugin from an HTML form?

I'm trying to build an RSVP form, and am not having a lot of luck with different field types.


Using the syntax from Brad's answer is working to create rows in the table on new entries, but it's not populating them. The below code creates two rows in the table, but they're empty.

<input type="text" name="fields[guests][0][name]" placeholder="Name" />
<input type="text" name="fields[guests][1][name]" placeholder="Name" />
8

See here for example front-end HTML code for all of Craft's default field types: https://straightupcraft.com/articles/craft-cms-field-guide-twig?view=input

Matrix:

{# You need to include the 'type' input to identify the matrix block type you are submitting #}
<input type="hidden" name="fields[fieldHandle][new1][type]" value="contacts">

{# All of your custom fields must be within a 'fields' array. #}
<input type="text" name="fields[fieldHandle][new1][fields][field1Handle]">
<input type="text" name="fields[fieldHandle][new1][fields][field2Handle]" >
<input type="text" name="fields[fieldHandle][new1][fields][field3Handle]" >

{# For New Entries, you'll want to use the naming convention 

'new1', 'new2', 'new3' for each of your blocks. For existing entries you can update those values to be the block IDs #}

Table:

<input type="hidden" name="fields[fieldHandle]" value="">
<textarea name="fields[fieldHandle][0][col1]" rows="1"></textarea>
<textarea name="fields[fieldHandle][0][col2]" rows="1"></textarea>
<textarea name="fields[fieldHandle][0][col3]" rows="1"></textarea>
<input type="hidden" name="fields[fieldHandle][0][col4]">
<input type="checkbox" name="fields[fieldHandle][0][col4]" value="1">

<textarea name="fields[fieldHandle][1][col1]" rows="1"></textarea>
<textarea name="fields[fieldHandle][1][col2]" rows="1"></textarea>
<textarea name="fields[fieldHandle][1][col3]" rows="1"></textarea>
<input type="hidden" name="fields[fieldHandle][1][col4]">
<input type="checkbox" name="fields[fieldHandle][1][col4]" value="1">

Lightswitch:

<input type="hidden" name="fields[fieldHandle]" value="1">
| improve this answer | |
  • I've updated the table example above, and the example in the linked field guide to reflect the col1 input naming that Ian describes below. – Ben Parizek Feb 20 '16 at 20:13
3

I was going out of my mind trying to work this out. William Isted spotted that Craft is using col1 as the fieldname in the table on the edit entry page. (You can see this in the inspector).

This is from /admin/entries/rsvps/92-test

<textarea name="fields[guests][0][col1]" rows="1" style="min-height: 46px;">Ian</textarea>

If I switch my forms column1Handle to col1 it saves the entry and shows the data in Craft.

You can see from the database it was saving previous data under the column1Handle (e.g. name), however Craft wasn't using that handle to retrieve the data.

I guess the tables on the entry pages are either looking for the wrong fieldnames, or the example code is wrong, and should read:

<textarea name="fields[fieldHandle][0][col1]" rows="1"></textarea>
<textarea name="fields[fieldHandle][0][col2]" rows="1"></textarea>
<textarea name="fields[fieldHandle][0][col3]" rows="1"></textarea>

Hope this helps save someone else the same headache I've just gone through.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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