Skip to content

File size for nullable field #160

@alaksandarjesus

Description

@alaksandarjesus

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions