Support

Account

Home Forums ACF PRO how to create front end form data add in post

Solving

how to create front end form data add in post

  • hi.

    i want to create a one membership form for front end. it will have many text filed, one text area, one image, some check-box filed. and i want to save my data member category as a post and status Pending.

    i made one already all filed.

    Show this field group if
    Page Template > is equal to > Application (my page template name)

    if my code like below then in front end all filed coming but after i submit not add data in admin.

    <?php acf_form_head(); ?>
    <?php 
    /*
    Template Name: Application
    */
    get_header(); ?>
    <div id="primary">
    		<div id="content" role="main">
    
    			<?php /* The loop */ ?>
    			<?php while ( have_posts() ) : the_post(); ?>
    				
    				<h1><?php the_title(); ?></h1>
    				
    				<?php the_content(); ?>
    				
    			<?php acf_form(); ?>
    
    			<?php endwhile; ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
        
    <?php get_footer(); ?>
    

    i want save my data under members category and status pending how … can you guys help me out please

  • The data that was added was probably added to the page the form was shown on.

    You need to include several other options in your value and possibly add a hook

    Look at this documentation http://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/ for creating a new post of a different post type and you’ll need to read this http://www.advancedcustomfields.com/resources/acf-pre_save_post/ for altering the post status of you’re new post.

  • i tried already base on ref. link already but not success yet. may be i am missing something. i already made support ticket with my site details. also i am still trying.. let see. i will keep update

  • The first thing you’re going to need to add is field groups to the form call itself to even get the form to display, then you need to add specifics to tell ACF where to put the new post.

    
    <?php 
        $args = array(
            'field_groups' => array('group_678906ab8ec')),
            'post_id' => 'new_post',
            'new_post' => array(
                'post_type' => 'application ',
                'post_status' => 'pending'
             ),
            'submit_value' => 'Submit Application'
        );
        acf_form(); 
    ?>
    
  • i did.. not work. i added

    function my_pre_save_post( $post_id ) {
    
        // check if this is to be a new post
        if( $post_id != 'new' ) {
    
            return $post_id
    
        }
    
        // Create a new post
        $post = array(
            'post_status'  => 'draft' ,
            'post_title'  => 'A title, maybe a $_POST variable' ,
            'post_type'  => 'post' ,
        );  
    
        // insert the post
        $post_id = wp_insert_post( $post ); 
    
        // return the new ID
        return $post_id;
    
    }
    
    add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
    

    this to in function.php too it show me error line 120. which is `
    return $post_id
    }`

    my template file code is

    			<?php 
        $args = array(
            'field_groups' => array('members-field')), // Field Group name
            'post_id' => 'new_post',
            'new_post' => array(
                'post_type' => 'members ',  // category name
                'post_status' => 'draft'
             ),
            'submit_value' => 'Submit Application'
        );
        acf_form(); 
    ?>

    still waiting for support ticket response

  • Originally I thought you said that you had a custom post type.

    Adding the post to a category will be a little more complicated.

    The code in your template should be

    
    <?php 
        $args = array(
            'field_groups' => array('members-field')), // Field Group name
            'post_id' => 'new_post',
            'new_post' => array(
                'post_type' => 'post',
                'post_status' => 'draft'
             ),
            'submit_value' => 'Submit Application'
        );
        acf_form(); 
    ?>
    

    for the pre_save_filter something like the below, for this you’re going to need to know the category id

    
    unction my_pre_save_post( $post_id ) {
    
        // check if this is to be a new post
        if( $post_id != 'new' ) {
            return $post_id
        }
    
        // Create a new post
        $post = array(
            'post_status'  => 'draft' ,
            'post_title'  => 'A title, maybe a $_POST variable' ,
            'post_type'  => 'post',
        );  
    
        // insert the post
        $post_id = wp_insert_post($post); 
    
        $category_id = 0; // change this to your category ID
        wp_set_post_categories($post_id, array($category), false);
        // see WP codex for more information on wp_set_post_categories
    
        // return the new ID
        return $post_id;
    
    }
    
    add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
    
  • giving error. i think it is sytex error screenshot

    <?php acf_form_head(); ?>
    <?php 
    /*
    Template Name: Application
    */
    get_header(); ?>
    
    <div id="primary">
    		<div id="content" role="main">
    
    			<?php 
        $args = array(
            'field_groups' => array('members-field')), // Field Group name
            'post_id' => 'new_post',
            'new_post' => array(
                'post_type' => 'post',
                'post_status' => 'draft'
             ),
            'submit_value' => 'Submit Application'
        );
        acf_form(); 
    ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
        
        
    
    <?php get_footer(); ?>

    page-application.php on line 15

    in function bellow code also show error

     if( $post_id != 'new' ) {
            return $post_id
     	}

    but i made it like

     if( $post_id != 'new' ) {
            return $post_id;
     	}
    	

    now no error showing.

    i am sorry to say i am not so expert on php code yet. that’s why may be can not fix small small think.

    would you please see what’s wrong code

    also please see my screenshot from admin screenshot

    Show this field group if this setting ok or not ?

  • The color coding in DW does help, sorry, it’s not always easy to see the errors in plain text. The error is an extra closing ) on this line 'field_groups' => array('members-field')

    
    <?php acf_form_head(); ?>
    <?php 
    /*
    Template Name: Application
    */
    get_header(); ?>
    
    <div id="primary">
    		<div id="content" role="main">
    
    			<?php 
        $args = array(
            'field_groups' => array('members-field'), // Field Group name
            'post_id' => 'new_post',
            'new_post' => array(
                'post_type' => 'post',
                'post_status' => 'draft'
             ),
            'submit_value' => 'Submit Application'
        );
        acf_form(); 
    ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
        
        
    
    <?php get_footer(); ?>
    
  • thanks for quick response.. now no error. but not work. what is happening now let me explain you.

    did you see Show this field group if screenshot shot. if like that then form coming with value which i added last time. but i don’t know where those data add before. i never see any post like this in whole WordPress. so from that data coming i don’t know.

    but if Show this field group if setting different then form also no coming. same problem i face before.

    i sent already my site details to support to look at this. but never headed back yet. i am not you are from that support team or separate person. if you support them then would you please check this thing. it really impotent for me make this work. because similar for front end form submission i have more work. that’s why i want to upgrade my licences too.

  • what i want to do ??

    i have one category Members for that i already create custom field . when you create any new post if you select category Mambers then members filed will show. this is fine working

    now i want i will have one member application form in front end. example http://xxxxx.com/application-form/ same filed as member category filed. so when anyone fill and submit then it will save under Members category and draft mode. so later admin can review and make that publish. also if possible want to add form validation or capture for protection spam.

  • What is the group id of the field group. It should be something like

    group_abc123fedc12

  • thanks for respone. i tried wil group slug but not success. i attached all code screenshot. i sent my site details to support for check. i think if they see a bit problem will be fast. i have limited knowledge about php coding that’s why i ask so much question.

    application.php
    page-application.php

    function.php

    function.php

    WordPress admin

    wordpess admin

    front end result

    front end

    would you please see my issue.

  • It would be a lot easier if you posted code since it’s impossible to copy and paste code out of images and I have to type up everything manually.

    I am not involved in the support system where you submitted a trouble ticket. I just help out here on the forum answering questions.

    The problem appears to be that you have a different post_id value in your form arguments than you are testing for in the pre_save_post filter.

    in one place you have

    
    'post_id' => 'new_post',
    

    and in the other you have

    
    if ($post_id != 'new') {
    

    change them to the same value, either new_post or new so that you are checking for the same value that you are setting.

  • @John Huebner . i am sorry for not posting code. actually code post my previous post. thank you so much for your support. it is really great for us.

    actually i made ticket support with my site details. but support still not response. it about two days i think.

    i change new to new_post all id same now but in front end Form even not come. just come Update Button

    <?php acf_form_head(); ?>
    <?php 
    /*
    Template Name: Application
    */
    get_header(); ?>
    
    <div id="primary">
      <div id="content" role="main">
        <?php 
        $args = array(
            'field_groups' => array('group_559b4ee335078'), // Field Group name
            'post_id' => 'new_post',
            'new_post' => array(
                'post_type' => 'post',
                'post_status' => 'draft'
             ),
            'submit_value' => 'Submit Application'
        );
        acf_form(); 
    ?>
      </div>
      <!-- #content --> 
    </div>
    <!-- #primary -->
    
    <?php get_footer(); ?>
    

    function.php

    function my_pre_save_post( $post_id ) {
    
        // check if this is to be a new post
        if( $post_id != 'new_post' ) {
            return $post_id;
     	}
    	
        // Create a new post
        $post = array(
            'post_status'  => 'draft' ,
            'post_title'  => 'A title' ,
            'post_type'  => 'post',
        );  
    
        // insert the post
        $post_id = wp_insert_post($post); 
    
        $category_id = 3; // change this to your category ID
        wp_set_post_categories($post_id, array($category), false);
        // see WP codex for more information on wp_set_post_categories
    
        // return the new ID
        return $post_id;
    
    }
    
    add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
  • Check the field group ID, I may have typed that wrong when copying from the image. If there is no form and just a submit form it means that ACF is not finding the field group to display.

  • Thanks for quick reply.

    group id i copy and paste from group_559b4ee335078 slug. and my

    Show this field group if setting is

    is there any way can check in my site. i can send site details. but don’t want to post open in public

  • so the field group ID is wrong. The field group from the image has a slug of
    group_559b4ee3 not group_559b4ee335078

    
    <?php acf_form_head(); ?>
    <?php 
    /*
    Template Name: Application
    */
    get_header(); ?>
    
    <div id="primary">
      <div id="content" role="main">
        <?php 
        $args = array(
            'field_groups' => array('group_559b4ee3'), // Field Group name
            'post_id' => 'new_post',
            'new_post' => array(
                'post_type' => 'post',
                'post_status' => 'draft'
             ),
            'submit_value' => 'Submit Application'
        );
        acf_form(); 
    ?>
      </div>
      <!-- #content --> 
    </div>
    <!-- #primary -->
    
    <?php get_footer(); ?>
    
  • thanks.

    actuall group id not wrong. normally can not see full id. because input filed size was set in 13 that’s why show only 13 digit. but when you select the input filed value then it is select full value . i even try with your id but it is same.

    for just information i made screenshot from admin and remove input size 13, now u can see full id

  • From what I can see by looking that the code, except for making sure the group ID is correct, the code I gave you should be showing the form on the front of the site. If it isn’t then you have a problem somewhere other than the code to show the form.

  • Thank you much your great support. i tried many way but form even not come. tried something totally group filed form only if i make Show this field group if as page template but that way i think don’t work.

    my function.php even don’t have much work. i removed all code from function.php for test and keep acf code and css and jquery load code.. but result is same.

    thanks you again.

    can you tell where i can send mail for support. i email already support about it many time but not really response . i gave them my site info also for testing..

  • Instead of using the field group slug, try using the post_id of the field group

    you can get the id from the browser location bar

  • Hi guys.

    Just noticed that the acf_form function is not getting the $args array.

    Change
    acf_form();

    to:
    acf_form( $args );

  • Wow, I’m loosing my mind. I don’t usually miss little things like that. A sure sign that I’ve been looking at it too long and edited it too many times.

    Thanks E for poking your head in here.

  • This reply has been marked as private.
  • thank you very much both of you. i am now learning and trying.if i can fix then i will keep update here

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

The topic ‘how to create front end form data add in post’ is closed to new replies.