found one more issue .. when using the Basic File field on a front end form and the field not required, a new (empty) attachment is created even if no file is uploaded by the user
btw, i’ll keep logging them here to keep the issues together, but let me know if you’d rather i open a new post to compile the issues i’m finding
Found one more issue that other people might find helpful. The Basic File uploader fails validation if it is a required field. To solve this I hook into “acf/validate_field” like this (let me know if there is a better way):
jQuery(document).on('acf/validate_field', function( e, field ){
var $field = jQuery(field);
if( $field.find('input[type="file"]').exists() ) {
$field.data('validation', true);
if( $field.find('input[type="file"]').val() == '' ) {
$field.data('validation', false);
}
}
});
i think i found the issue – for some reason the following action is not being fired on the front end:
add_action('post_edit_form_tag', array($this, 'post_edit_form_tag'));
as a work around i use the form_attributes argument to the acf_form function when i create my front end form and it works perfectly
'form_attributes' => array(
'enctype' => 'multipart/form-data',
),
worked great on the backend but on a front end form the only thing that gets saved is the filename .. a new attachment post is not actually created
is this not supported in the field yet?
thanks ..
ps. this is really great and IMO a nice user experience for front end users than the WP media uploader
great thanks .. i was able to solve this by hooking “acf/location/match_field_groups” to set the $metabox_ids that i want to render
i can’t find that file .. is that in the current stable version?
in my scenario individual posts of a CPT may have different field groups associated with them
is there a way to render a field group in the edit screen for a CPT without using location rules?
i’m thinking i would hook into the “add_meta_box” action .. and i know the ID of the field group i want .. i’m just not sure how to use the ACF API to render the field group
ok thanks .. my issue was that I was trying to use “get_field_object” to access a sub field of a repeater
is it possible to directly access a sub field of a repeater with its key?
i was able to get to the field i needed without looping through all of the sub_fields like this but i’d rather use the api if there is a cleaner way:
$payment_object[‘sub_fields’][0]
hot damn! that worked perfectly
this plugin just keeps giving and giving…
many thanks
actually one other quick question – using this hook could I also change or add to the error message?
currently it displays: “Validation Failed. One or more fields below are required.”
I’d like to add something like – “Your email addresses do not match”
awesome – thanks .. I’m able to get this to work.
because this is triggered on every field my solution is a littly wonky for my specific use case (comparing values of 2 fields) – i had to traverse back up to the field’s parent to look for another field’s value
I’m wondering if in a future version you could add an additional hook that would be triggered after you loop through each required field so that other explicit validation conditions could be checked
either way I’ve got something working and I love this plugin!!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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.