1

I am attempting to create a front-end form utilising Craft CMS matrix fields and the dropdown/table field options. I have a matrix field called 'course', this has a Block Type called 'course' and this has two fields, 1. 'courseTitle', this is a dropdown field and 2. 'stage1CourseBookingForm' this is a table field, inside this table field I have a column called 'courseType' which is a dropdown. How can I achieve this?

This is my code currently, I get this error: "Impossible to access an attribute ("settings") on a null variable."

{% for block in entry.course %}

{% set entry = entry ?? create('craft\\elements\\Entry') %}

<form method="post" accept-charset="UTF-8">
{{ csrfInput() }}

<input type="hidden" name="action" value="entries/save-entry">
<input type="hidden" name="sectionId" value="1">
<input type="hidden" name="enabled" value="1">
<input type="hidden" name="entryId" value="{{ entry.id }}">
<input type="hidden" name="fields[course]"/>


<input type="hidden" name="fields[course][{{ block.id }}]. 
[type]" value="course">
<input type="hidden" name="fields[course][{{ block.id }}]. 
[enabled]" value="1">


{% set dropdownField craft.fields.getFieldbyHandle('courseTitle') %}
<select class="form-control" id="courseTitle" name="fields[courseTitle]">

{% for option in dropdownField.settings.options %}
<option {{ entry.courseTitle.value == option.value? 'selected' : '' }} value="{{ option.value }}">{{ option.label }}</option>
{% endfor %}
</select>`

<button type="submit">Publish</button>
</form>
  • Please provide enough code so others can better understand or reproduce the problem. – Tom Oct 25 '21 at 18:49
  • Hello, I have added my code. Thank you. I get this error "Impossible to access an attribute ("settings") on a null variable." – SynecdocheNORTH Oct 28 '21 at 16:44
  • At a quick glance, `set dropdownField craft.fields.getFieldbyHandle('courseTitle')` is missing the `=`, should be `set dropdownField = craft.fields.getFieldbyHandle('courseTitle')` ... though beyond that I'm unsure if the code will work without looking closer — that's just the source of the particular error you're asking about. – Nate Beaty May 18 '22 at 15:19

0 Answers0