Home › Forums › Front-end Issues › javascript error with image in front end
I make front end form to make/edit a post.
but it doesn’t work especially with uploading images. (didn’t try uploading files yet)
when I try to click [add image] button, it returns javascript error like below.
===
Uncaught TypeError: Cannot read property ‘post_id’ of undefined
(input.php?ver=4.1.8.1:1143)
===
which is this part…
// library
if( this.o.library == 'uploadedTo' )
{
this.o.query.uploadedTo = acf.o.post_id;
}
I already set my image type field to [uploaded to post].
It doesn’t work for uploading new files and deleting existed files.
do you have any idea?
i put acf_form_head() before get_header();
my code basically is:
$post = get_post(get_the_ID()); // of course i did wp_query() and the_post() first
$options = array(
'post_id' => $post->ID, // post id to get field groups from and save data to
'field_groups' => array(), // this will find the field groups for this post (post ID's of the acf post objects)
'form_attributes' => array( // attributes will be added to the form element
'class' => ''
),
'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
'html_field_open' => '<div>', // field wrapper open
'html_field_close' => '</div>', // field wrapper close
'html_before_fields' => '', // html inside form before fields
'html_after_fields' => '', // html inside form after fields
'submit_value' => 'edit', // value for submit field
'updated_message' => 'edited', // default updated message. Can be false to show no message
);
acf_form( $options );
which is nothing special.

Hi @summerz
The issue looks to be the acf_form_head is the function which generates the javascript variables acf.o.post_id
It seems that because you are customizing the post object, this is most likely not being set correctly by the acf_form_head function.
Can you take a look at the source / firebug and make sure the acf javascript variable exists and contains the acf.o.post_if value?
I wrote about this in diffrent post.
http://support.advancedcustomfields.com/forums/topic/front-end-form-with-file-gallery-uploaders/
Short solution to clear errors:
acf.o = {};
acf.screen = {};
acf.o.post_id = 0;
acf.screen.post_id = 0;
The topic ‘javascript error with image in front end’ is closed to new replies.
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.