Current status: Solved. . Done
Front End User Profile Field Form Causes ReferenceError
  • I am using ACF to allow users to modify their user profile from the front end. When I add this code:
    	$options = array(
    'post_id' => 'user_'.$userID,
    'field_groups' => array($field_group['ID']),
    'submit_value' => 'Save All Changes',
    'updated_message' => false
    );
    acf_form( $options );

    it works great except that I get a js "Uncaught ReferenceError: user_[$userID] is not defined". It seems to me that this is happening when ACF tries to set the post ID equal to the given post ID expecting a number but gets a string.

    Thanks for all your great work!
  • Hi @tannerm,

    Thanks for the bug report. I'll test it out myself

    Cheers
    Elliot
  • Hi,

    From what I saw (I encountered a similar bug), it seems it comes from the fact that post_id expects an integer and is, therefore, not wrap within quotes.

    See the JS generated by the acf_form() function below.
    <script type="text/javascript">acf.post_id = test; acf.nonce = "b2d991a840";</script>


    As you see, test is here not wrapped within quotes so it's considered as a variable (which doesn't exist). That's what triggers the error.

    Don't know if it will help you, but I thought I'd share this.
  • Hi @YPGabel,

    Awesome find. I'll get this fixed ASAP

    Cheers
    Elliot
  • Hi @tannerm, @YPGabel,

    This has been fixed and pushed to the latest nightly build on github

    Cheers
    Elliot
  • Hi @admin,

    Thanks :) I'll test this as soon as I can.
  • Awesome! Thanks @admin!!

    -Tanner