1

I created a matrix with 1 type, 3 fields for user profile. I use front-end to upload file to documentUpload field. But I got PHP warning: array_merge(): Argument #1 is not an array message. I Google it and see this issue. I did try adding

if (empty($value)) {
    $value = array();
}

But I still got the same issue. Not sure how I could resolve the issue. I see my file is uploaded to AWS S3. Looks it has issue to save it in Craft. Does anyone know how to solve it? Thanks

Here is my code to upload file:

<form method="post" accept-charset="UTF-8" enctype="multipart/form-data">
 {{ getCsrfInput() }}
<input type="hidden" name="action" value="users/saveUser">
<input type="hidden" name="fields[petRecords][new{{ next }}][type]" value="records">
<input type="hidden" name="fields[petRecords][new{{ next }}][enabled]" value="1">
<input type="file" name="fields[petRecords][new{{ next }}][fields][documentUpload]" />
<input type="text" name="fields[petRecords][new{{ next }}][fields][description]" />
<input type="text" name="fields[petRecords][new{{ next }}][fields][petIdNumber]" />
<input class="btn btn-primary btn-block btn-social" type="submit" value="continue">
</form>

configuration My Craft CMS version is 2.6.2980 Error message

7
  • 1
    Have you tried passing your file field as an array, adding [] at the end?fields[petRecords][new{{ next }}][fields][documentUpload][]
    – Matt Stein
    May 26 '17 at 17:09
  • You're linking to an amforms plugin issue. Is this an amforms form? Doesn't look like it because it's calling users/saveUser.
    – Brad Bell
    May 26 '17 at 17:24
  • @matt-stein, Adding [] looks that issue is gone. but when I enter another file, I got error. After I refresh my page and add the file again, it allows me to add a file. Looks the tagetID is not loaded on the first time. May 26 '17 at 18:28
  • CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'targetId' cannot be null. The SQL statement executed was: INSERT INTO craft_relations` (fieldId, sourceId, sourceLocale, targetId, sortOrder, dateCreated, dateUpdated, uid) VALUES (:row0_col0, :row0_col1, NULL, NULL, :row0_col4, :row0_col5, :row0_col6, :row0_col7). Bound with :row0_col0='98', :row0_col1='522', :row0_col4=1, :row0_col5='2017-05-26 18:22:39', :row0_col6='2017-05-26 18:22:39', :row0_col7='75187a4d-f2fc-4389-9c35-f42b9ba1f17c'` May 26 '17 at 18:28
  • 1
    I see your new question here, @AngelaChan. Can you add the [] fix as an answer to this one in case other people might have the same issue?
    – Brad Bell
    May 26 '17 at 23:41

Your Answer

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

Browse other questions tagged or ask your own question.