Support

Account

Home Forums ACF PRO Adding my custom fields to existing front-end post/update form

Solving

Adding my custom fields to existing front-end post/update form

  • Hi There,

    I am attempting to integrate ACF Pro with the Listify theme. I have added in a number of custom fields via a field group and these fields appear when adding or editing a listing in the ADMIN AREA. I am also displaying all of these fields on the front-end theme without any issue.

    The Listify Theme also includes the ability for front-end users to submit a listing, or edit a listing. They have their own form for that and their own series of custom fields that exist outside of ACF.

    I need to display my ACF Pro fields at the bottom of their front-end form so that these fields can be filled out or edited when submitting or editing a listing.

    If I add the following code at the bottom of the form, I can get my custom fields to appear:

    <?php acf_form(array(
    ‘field_groups’ => array(2161),
    ‘form’ => false
    ));?>

    The problem is, no matter what I do, I cannot get the custom fields to save when submitting the listing / updating the listing.

    I have identified where to hook into the “save” function provided by listify, and for example I can do this:

    function woohoo() {
    echo “woohoo”;
    }
    add_action( ‘job_manager_update_job_data’, ‘woohoo’, 10, 2 );

    The form saves and then when the page reloads it echo’s “woohoo” at the top, so I believe I am hooking in to the write function.

    So, I thought it would be a case of adding “do_action(‘acf/save_post’, $post_id);” to a function and then adding that function via my action (I got this idea here http://support.advancedcustomfields.com/forums/topic/front-end-and-custom-user-meta/), but doing this results in an error when the page is reloaded:

    Warning: Invalid argument supplied for foreach() in /home/resul/public_html/wp-content/plugins/advanced-custom-fields-pro/core/input.php on line 48

    I have been scouring the support forums and various other loctions on the net for about 6 hours at this point looking for a solution but I am at my whits end and thought I would try opening a ticket here to see if I can get some support here.

    Thanks
    Zach

  • Not sure if you’re still looking or have figured something out, but just in case someone is trying to do something similar.

    Without seeing the code or knowing the theme you’re talking about I would guess that this is because there are 2 different forms.

    There are a couple of choices, and to be honest I don’t know if either of them will actually work.

    The first is to find a way to add inputs into the theme form and then use the ACF update_field() function to save the fields when the form is submitted. The problem here is getting your new fields into an existing form.

    The second would be to see if you can add the theme fields to an ACF field group. If the fields are stored in the postmeta table this could be done by duplicating the field names used by the theme, this would cause ACF to save the fields when the ACF form is submitted. The problem here is there may be some problem on the back end where these fields appear twice.

  • @zachnicodemous

    Did you ever find a working solution?

    I want to add an ACF repeating field to the WP Job Manager form used in Listify. Anything you can share would help πŸ˜‰

    To update, I’m using child theme and am inserting the fields:

    add_filter( 'submit_job_form_fields', 'frontend_add_custom_fields' );
    
    function frontend_add_custom_fields( $custom_fields ) {
    
    $custom_fields = acf_form(array(
    'field_groups' => array(882),
    'form' => false	));
    
    return $custom_fields;
    }
  • Hi @all,
    has anyone found a solution for that already?
    I use the WP Residence Theme and have a similar issue, that I would like to add ACF to the fron-end submit form of the theme.
    Any help or solutions would be greatly appreciated.

    Thanks in advance πŸ™‚

  • To all those asking, I did eventually solve this problem for my client at the time. It was admittedly a bit of a “hack” solution, not the cleanest code in the world, but it worked well and its still functioning well today.

    I am more than happy to implement a similar solution for anyone in the same kind of scenario – I can be hired via Codeable at https://codeable.io/developrs/zach-nicodemous/

  • @zachnicodemous

    It’s not a cool move to come onto a support forum to ask for FREE help and then offer a solution for a fee.

  • I didn’t know this when I first commented on this topic. If you have the ability to edit the existing front end form you can use acf_form() with the “form” option set to false https://www.advancedcustomfields.com/resources/acf_form/. Put the acf_form call inside of the existing form.

  • I’ve just revisited this and thought I’d share in detail how I did it. It’s an application of John’s thinking.

    My problem to begin with was I wanted to add a repeating field to the job submission form of WP Job Manager (specifically in Listify – should work across other themes)

    Create your field group containing the repeating fields and grab the field group ID. You can find this in the URL of the edit field group page for your field group under Custom Fields.

    In your theme or child theme, create a folder called job_manager, and copy in job-submit.php from plugins/wp-job-manager/templates. This will be used instead of the default job submission form.

    Paste in the following code where you would like the repeating field to appear. I chose line 51 so it would appear after all other fields. I haven’t tested other locations but I guess it should work.

    <?php acf_form(array(
        'post_id'	=> $job_id,
        'field_groups' => array(your field group ID num here),
        'form' => false,
        'return' => '' // do not redirect, let WP Job Manager take care of it
    )); ?>

    Without using a blank return you get issues with the page not redirecting to the proper URL and display submission success messages.

    I had issues with acf_form_head() so am adding it in functions.php. You could always add a check to just add it if on a certain URL, using a template etc. Simply though:

    add_action( 'init', 'acf_head_add' );
    
    function acf_head_add(){
        acf_form_head();
    }

    Hope that helps.

  • I followed James instructions:

    Showing custom fields works perfectly fine. As soon as I add the lines

    add_action( 'init', 'acf_head_add' );
    
    function acf_head_add(){
        acf_form_head();
    }

    to my functions.php I get the white screen on submitting the post.

    Does anyone know what to do about that?

  • I put my acf_form(‘form’ => false, etc.) into the existing form. When I submit this form with button submit, the ajax action: acf/validate_save_post fires, and nothing updates. When I remove my acf_form() from form element, ajax action doesn’t fire and all works correct. Why does it happen. Thank you.

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

You must be logged in to reply to this topic.