-
Notifications
You must be signed in to change notification settings - Fork 149
Open
Description
I am collecting an array of images from multipart/form-data
<table class="table table-bordered">
<tbody>
<tr>
<th>Primary Image</th>
<td>
<input type="file" name="primary" class="primary" accept="image/*">
</td>
</tr>
<tr>
<th>Image - 1</th>
<td>
<input type="file" name="images[]" class="images">
</td>
</tr>
<tr>
<th>Image - 2</th>
<td>
<input type="file" name="images[]" class="images">
</td>
</tr>
<tr>
<th>Image - 3</th>
<td>
<input type="file" name="images[]" class="images">
</td>
</tr>
<tr>
<th>Image - 4</th>
<td>
<input type="file" name="images[]" class="images">
</td>
</tr>
</tbody>
</table>
and my validator is
$rules = [
'nonce' => 'required|nonce',
'uuid' => 'required',
'primary' => 'required|min:1000000|max:5000000|mimes:jpg,jpeg,png,webp',
'images.*' => 'nullable|min:1000000|max:5000000|mimes:jpg,jpeg,png,webp',
];
$errors = $validator->validate($_GET + $_POST + $_FILES, $rules);
if (!empty($errors)) {
wp_send_json_error(['message' => $errors]);
}
The rule is primary image is required and rest of the images are optional. So I have mentioned them as nullable.
The issue is at images.* when I do not select any images, they are not passing, as the minimum requirement is 1MB. But my post call is having the empty file selector reference.
Metadata
Metadata
Assignees
Labels
No labels