Advansed Custom Fields Frontend form

Home Forums Support Advansed Custom Fields Frontend form

Home Forums Support Advansed Custom Fields Frontend form

  • This topic has 7 replies, 3 voices, and was last updated 6 years ago by Tom.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #176526
    Oleg

    Hello!
    I use plugin Advansed Custom Fields. I want to create frontend form, but I do not want to change the template files. It is necessary to add a function:

    acf_form_head();

    to the beginning of page, for example:

    <?php
    /**
     * The template for displaying all pages.
     *
     * This is the template that displays all pages by default.
     * Please note that this is the WordPress construct of pages
     * and that other 'pages' on your WordPress site will use a
     * different template.
     *
     * @package GeneratePress
     */
     
    acf_form_head();
    
    get_header(); ?>
    
    	<div id="primary" <?php generate_content_class();?>>
    		<main id="main" <?php generate_main_class(); ?>>
    			<?php do_action('generate_before_main_content'); ?>
    			<?php while ( have_posts() ) : the_post(); ?>
    
    				<?php get_template_part( 'content', 'page' ); ?>
    
    				<?php
    				// If comments are open or we have at least one comment, load up the comment template
    				if ( comments_open() || '0' != get_comments_number() ) : ?>
    					<div class="comments-area">
    						<?php comments_template(); ?>
    					</div>
    				<?php endif; ?>
    
    			<?php endwhile; // end of the loop. ?>
    			<?php do_action('generate_after_main_content'); ?>
    		</main><!-- #main -->
    	</div><!-- #primary -->
    
    <?php 
    do_action('generate_sidebars');
    get_footer();

    Here is the documentation on this page: http://www.advancedcustomfields.com/resources/create-a-front-end-form/.

    My question is: is it possible to add this feature with the hooks? I tried to insert, but it is not working properly.

    #176628
    Tom
    Lead Developer
    Lead Developer

    Not sure if it will work, but you can try it in the “Above Header” hook like this:

    <?php acf_form_head(); ?>

    Make sure to check “Execute PHP”.

    #176636
    Oleg

    This function works, but is not entirely correct. Maybe there is another way?

    #176726
    Tom
    Lead Developer
    Lead Developer

    Hmm I’m not sure – I don’t have any experience with the plugin.

    You may need to do it as they say I’m afraid.

    #549186
    Tomáš

    Hi Tom,

    amazing theme! If you could just add one more hook into GP premium, it would be amazing!

    This hook should be something like “Before header HTML”.

    This is beginning of your code in header.php

    
    <?php
    /**
     * The template for displaying the header.
     *
     * @package GeneratePress
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly.
    }
    
    ------ HERE SHOULD BE THE EXTRA HOOK ------
    
    ?><!DOCTYPE html>
    <html <?php language_attributes(); ?>>
    <head>
    	<meta charset="<?php bloginfo( 'charset' ); ?>">
    	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
    	<link rel="profile" href="http://gmpg.org/xfn/11">
    	<?php wp_head(); ?>
    </head>

    If you will create one more hook in the position marked as “—— HERE SHOULD BE THE EXTRA HOOK ——“, you will enable the front-end posting feature with Advanced Custom Fields plugin, because that’s exactly the place, where should “acf_form_head();” function be placed.

    Thanks in advance!

    #549629
    Tom
    Lead Developer
    Lead Developer

    According to their docs (https://www.advancedcustomfields.com/resources/acf_form_head/), you should be able to place that in the Before Header or wp_head hook 🙂

    #549652
    Tomáš

    When I place it inside one or the other hook, after form is submitted it returns the “Headers already sent” error.

    I did already give it a try, that is why I asked you to add the extra hook.

    Also according to their docs, they say:

    This function must be placed before any HTML has been created…

    If you won’t add the hook, I’ll understand. I’m using currently a workaround with child theme, where I copy the original header.php, it’s not so super important update, I just thought it will be appreciated also by other ACF users. 😉

    #549975
    Tom
    Lead Developer
    Lead Developer

    It might be worth contacting them directly and asking. By HTML, do they mean before the actual <html> element? If so, I will definitely consider it 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.