Support

Account

Home Forums Front-end Issues Upload (in Frontend) won't save file

Solving

Upload (in Frontend) won't save file

  • Hi,

    with acf_form I try to save a text field and a file into my custom post type. Unfortunately in vain. The file is not saved.

    However, the text field (name) is saved.

    My code:

                    $fields = array(
                        'field_5e79ce9fce16f', // name
                        'field_5e79deb62bcea' // file
                    );
                    acf_form(array(
                        'post_id'           => 'new_post',
                        'new_post'          => array(
                            'post_type'     => 'usertasks',
                            'post_status'   => 'publish',
                            'post_title'    => get_the_title( $post->post_parent ) . ' - ' . get_the_title(),
                        ),
                        'uploader'          => 'basic',
                        'fields'            => $fields,
                        'submit_value'      => 'Eintrag speichern',
                        'updated_message'   => 'Eintrag wurde gespeichert',
                        'html_after_fields' => '<input type="hidden" name="acf[field_5e79d81e6e229]" value="'.get_the_ID().'"/>',
                    ));

    Attached a screenshot of my ACF fields.

    Maybe someone has an idea why the file is not saved?

    Many Thanks
    André

  • I still haven’t made it.

    If I var_dump the POST variable, the file (test.pdf) also appears. But is still not saved. But the name (Dummy Name) does.

    Am I missing anything?

    function UserTaskPreSave( $post_id ) {
        var_dump($_POST);
        exit();
    }
    add_action( 'acf/save_post', 'UserTaskPreSave');
    
    
    array(7) {
      ["_acf_screen"]=>
      string(8) "acf_form"
      ["_acf_post_id"]=>
      string(8) "new_post"
      ["_acf_validation"]=>
      string(1) "1"
      ["_acf_form"]=>
      string(1848) "aS9JT0h2T2VKUG94YTRQUlZiNWxwcExSQ0c5MlN2YXhMVjJBS2JqSVJUeEREREFFeERLTnh0SVRtYVZBOGVTOTV6blQ3eWMyY1hlMVRRSTEvMHNjYytxcUwxY0d6d3o0OHdUZWI1RXJyNkVJR1NoL2hValgrQXBUWnJvcW40YnR1d3FndElEWENNenpPRzJObkNiSGRBNEpMUHEwWkExeFhKNWhScmk2bXRpY3FnK294NmNKWVZpYWhWKzFaOXkxQU1EUkNPVkI3cmJTa0EvdUc1b1N0cVRZamtVbVR4SU9FQmUyb1kvQlhLWDNOc25ZR0JsNmNKSUN2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EZRYU1tL3l2V1NrWmh4QmVhVmJnUEs5RUMrWk1Ob1V2OERGWTYrUG91SWtjZ3NoMnBybE9uaCtxSDM3REpoTHFrenNIak14bXZXN2FvYVRYMnA2NEpta3J4akVuU0x5NzNNUGNnZnRMc281T2ZhSXNxbGVqVEMvVkdRNXlEcjd1eStSeXFyQU9IVUFsSTE1MjM4VU10NE91WEZFdW90SHJ1RXNtUmdnbGFxZzlwczZFekVYMllYSnMxclpVejZ5Lzhibk9nRW41Zy9rS2szbGpKNnZ0cEJab2VmYm4wN1JiOGZEQUd2WVVPR1NmRHRieWQ5NDJoQmUwZ0p5ekJlY0RzNGRKMHdldXVNS1hRdVJzQjhQNkJpNG1BNXNKY1BqY3QzTjdKMTBqQmMyaWFYMm1xcFNCVnY3ZEZWOHozcDl4UT09Ojp8rT1IWuvTPFx2O8HhRHXC"
      ["_acf_nonce"]=>
      bool(false)
      ["_acf_changed"]=>
      string(1) "1"
      ["acf"]=>
      array(4) {
        ["field_5e79ce9fce16f"]=>
        string(11) "Dummy Name "
        ["field_5e79deb62bcea"]=>
        string(8) "test.pdf"
        ["_validate_email"]=>
        string(0) ""
        ["field_5e79d81e6e229"]=>
        string(3) "802"
      }
    }

    Thanks.
    André

  • The error has been found – at least it is working now.

    I apparently had to add the “form_attributes / enctype”.

    'form_attributes' => array(
    'enctype' => 'multipart/form-data',
    )

    Do you know that? Is this documented? I hadn’t seen that.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.