Search code examples
octobercms

October CMS' Magic Forms plug-in how to catch multi select values?


I have a multi select field in a complex form. It's works on the Magic Forms. But Magic Forms only handle multi select's values last one.

An example

                  <select required multiple id="..." name="...">
                    <option value="HTML">
                      HTML
                    </option>
                    <option value="CSS">
                      CSS
                    </option>
                    <option value="JavaScript">
                      JavaScript
                    </option>
                    <option value="Node.js">
                      Node.js
                    </option>
                  </select>

If I select HTML & CSS options, Magic Forms handle and record only the CSS option. I searched little bit, but I can't it. Is there a method?


Solution

  • It's possible you just need to make minor adjustments with the select name.

    Ref : Multiselect in OctoberCMS Magic Form

    As when you select multiple items it becomes an array. to represent the array on the HTML side you need to add [] square braces to the name.

    Suppose your current select name is tech So your select name becomes tech[] as now we are representing multiple values so it becomes an array.

    <select required multiple id="tech" name="tech[]">
    <!--                     USE name like THIS ^ -->
      <option value="HTML">
        HTML
      </option>
      <option value="CSS">
        CSS
      </option>
      <option value="JavaScript">
        JavaScript
      </option>
      <option value="Node.js">
        Node.js
      </option>
    </select>
    

    It will work and in backend records, it will show something like this :

    magic-form-backend-record-list

    If any doubt please comment.