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

Wrong error message when field is required #17

Closed
michael-e opened this Issue Sep 29, 2014 · 4 comments

Comments

Projects
None yet
2 participants
@michael-e
Member

michael-e commented Sep 29, 2014

When the field is required, an attempt to save an entry from the frontend without any file will result in something like the following:

<events>
    <my-section result="error">
        <filter name="permission" status="passed" />
        <message>Entry encountered errors when saving.</message>
        <image label="Image" type="invalid" message="'Image' is a required field." />
        <post-values>
            <title>My Title</title>
            <date>2014-09-21 17:10</date>
            <image>
                <error>4</error>
            </image>
        </post-values>
    </my-section>
</events>

I tried to find out why I get type="invalid" while the error message is correct—to no avail. Maybe @brendo has an idea? Or somebody else?

@brendo

This comment has been minimized.

Show comment
Hide comment
@brendo

brendo Oct 31, 2014

Member

This actually also affects the core Upload field as well. The reason being is that the check for determining the type is fairly crude. We basically attempt to reduce the data passed for the field. If it amounts to nothing, it's considered missing. If there is something there, and we have an error, it assumes it's invalid. Because of the way uploads work, there is always data for an upload field, even if it's just the 'error' node to say something went wrong. Because the data given is no longer technically 'empty', the field is marked as invalid.

Member

brendo commented Oct 31, 2014

This actually also affects the core Upload field as well. The reason being is that the check for determining the type is fairly crude. We basically attempt to reduce the data passed for the field. If it amounts to nothing, it's considered missing. If there is something there, and we have an error, it assumes it's invalid. Because of the way uploads work, there is always data for an upload field, even if it's just the 'error' node to say something went wrong. Because the data given is no longer technically 'empty', the field is marked as invalid.

@brendo

This comment has been minimized.

Show comment
Hide comment
@brendo

brendo Oct 31, 2014

Member

I've got a fix, I'll push it into the next version of Symphony (not 2.5.2, wouldn't want to break anything). If you need this now, add the following to event.section.php:

    // Do a little bit of a check for files so that we can correctly show
    // whether they are 'missing' or 'invalid'. If it's missing, then we
    // want to remove the data so `__reduceType` will correctly resolve to
    // missing instead of invalid.
    // @see https://github.com/symphonists/s3upload_field/issues/17
    if (isset($_FILES['fields']['error'][$field->get('element_name')])) {
        $upload = $_FILES['fields']['error'][$field->get('element_name')];
        if ($upload === UPLOAD_ERR_NO_FILE) {
            unset($fields[$field->get('element_name')]);
        }
    }
Member

brendo commented Oct 31, 2014

I've got a fix, I'll push it into the next version of Symphony (not 2.5.2, wouldn't want to break anything). If you need this now, add the following to event.section.php:

    // Do a little bit of a check for files so that we can correctly show
    // whether they are 'missing' or 'invalid'. If it's missing, then we
    // want to remove the data so `__reduceType` will correctly resolve to
    // missing instead of invalid.
    // @see https://github.com/symphonists/s3upload_field/issues/17
    if (isset($_FILES['fields']['error'][$field->get('element_name')])) {
        $upload = $_FILES['fields']['error'][$field->get('element_name')];
        if ($upload === UPLOAD_ERR_NO_FILE) {
            unset($fields[$field->get('element_name')]);
        }
    }
@michael-e

This comment has been minimized.

Show comment
Hide comment
@michael-e

michael-e Oct 31, 2014

Member

This actually also affects the core Upload field as well.

Indeed, I completely missed that.

I've got a fix, I'll push it into the next version of Symphony

I tested this fix with the core Upload field using Symphony 2.5.2-rc.1. Confirmed!

Member

michael-e commented Oct 31, 2014

This actually also affects the core Upload field as well.

Indeed, I completely missed that.

I've got a fix, I'll push it into the next version of Symphony

I tested this fix with the core Upload field using Symphony 2.5.2-rc.1. Confirmed!

@michael-e

This comment has been minimized.

Show comment
Hide comment
@michael-e

michael-e Oct 31, 2014

Member

Closing this, because it is a core issue.

Member

michael-e commented Oct 31, 2014

Closing this, because it is a core issue.

@michael-e michael-e closed this Oct 31, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment