Home Forums Front-end Issues Image selection on front end forms not working


Image selection on front end forms not working

  • TL/DR: The media selector when used on the front end is not fully respecting the “library: uploaded to post” setting, and the image selected is not being saved from a front-end submission if a cloned field is being used.

    I have a field group which includes a cloned field to select a featured image. The field is set to only select from images uploaded to the post, and to save the uploaded image id as _thumbnail_id (ie set it as the post featured image). The field group is being used both in the wp-admin area for editing the CPT, and also as a front-end submission form for creating new CPT posts.
    Within the admin area, the field works exactly as expected – clicking the “add image” button on a new post brings up the WP uploader, with no images to select; I have to upload the image I want to use.
    On the front end though, the WP media uploader seems to ignore the “uploaded to post” setting, and shows images available on the server – but doesn’t use ajax loading to fetch more images on scrolling. If I select an already uploaded image and save the form it appears to attach the image to the new post, but doesn’t save the image ID in the _thumbnail_id meta. This is apparent as going to edit the new post in the wp-admin area (a) doesn’t show an image as selected for the featured image; and (b) if I click the “add image” button, it shows the previously selected image as one that can now be selected.

    A few things that may be affecting this:
    1) the submission form is being created through the WooCommerce memberships my_account area
    2) I have used an init action hook to add the acf_form_head() function, rather than adding it in to the template files

    Settings for the Feature Image field:

    Field Label: Feature Image
    Field Name: _thumbnail_id
    Field Type: Image
    Required: No
    Return Value: Image ID
    Library: Uploaded to post

    all other settings at their default

    Settings for CPT form field group:

    Field label: Feature Image
    Field Name: _thumbnail_id
    Field Type: Clone
    Required: Yes
    Fields: All fields from Feature Image field group
    Display: Seamless (replaces this field with selected fields)
    Prefix Field Labels: No
    Prefix Field Names: No

    code used in the template file for the front end submission:

    		'post_id' => 'new_post',
    		'new_post' => [
    				'post_type' => 'goc_article',
    				'post_status' => 'pending'
    		'post_title' => true,
    		'field_groups' => ['group_5ae10dbfd6ade','group_5ae201392e590'],
    		'submit_value' => 'Submit news article'

    After submitting from the front end, all meta fields are correctly set *except* for _thumbnail_id which is empty, with *no extra* meta fields appearing in the database (ie it isn’t being saved as something else)

    I have tried:
    1) changing the featured image from a clone to a standard image field: the image ID is saved as the _thumbnail_id meta, but the media library still shows images not uploaded to post
    2) changing Library from “Uploaded to post” to “All”: works as would be expected.

    I don’t want users to be able to select any existing images when submitting a new item, so the Uploaded to post setting is important – especially as I have the same issue with a gallery selector as part of a flexible content field, I don’t want to have to revert to lots of file uploads!

    Being able to use a clone field is desirable, but not essential. It would certainly make it easier to keep Feature Image standards consistent accross all field groups where they are used!

Viewing 1 post (of 1 total)

The topic ‘Image selection on front end forms not working’ is closed to new replies.