Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File size for nullable field #160

Open
alaksandarjesus opened this issue Mar 9, 2024 · 0 comments
Open

File size for nullable field #160

alaksandarjesus opened this issue Mar 9, 2024 · 0 comments

Comments

@alaksandarjesus
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant