Support

Account

Home Forums Front-end Issues Simple, front-end form for a single field?

Solving

Simple, front-end form for a single field?

  • Does anyone have any experience with using acf_form to update a single field? I just need to have a single field on the front end that when they hit submit, it updates a specific custom field with what they put in.

    Note, I am using a custom post type for the pages it will be used on. I am also hoping to find an update-proof solution. That way I won’t have to worry about having to manually update a custom template to ensure it is on par with the default. Something where I can use my functions.php file to inject the header tag for the form and for injecting the form itself into the page content where I want it. Something like a shortcode.

    Is this even possible?

  • acf_form() allows setting to only include selected fields, see the fields option https://www.advancedcustomfields.com/resources/acf_form/

    To add the acf_form_head() call to a specific template you could do this on the WP get_header hook with a low priority

    
    // include when template is page.php
    add_action('get_header', 'include_acf_form_head', 1);
    function include_acf_form_head() {
      global $template;
      $file = substr($template, strrpos($template, '/')+1);
      if ($file == 'page.php') {
        acf_form_head();
      }
    }
    

    Your problem is going to be inserting the form into the page without modifying the theme. WP has not hooks, filters or actions that happen in the content area of the page that will allow you to call a function. The closest thing that you’ll get is the_content. Unfortunately, this is run on every WYSIWYG editor.

    Another choice, which is new today https://support.advancedcustomfields.com/forums/topic/create-front-end-form-using-shortcode/#post-38293

  • Yeah…that’s my hurdle there…getting it into the content. That’s why I was wondering if anyone has been successful in turning that part into a shortcode so I can just create the shortcode in my functions file.

    I did check out that link and left a message for an example. Will update here should it work as I need it to.

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

The topic ‘Simple, front-end form for a single field?’ is closed to new replies.