Support

Account

Home Forums Front-end Issues ACF form

Solving

ACF form

  • hi ,

    I try to use ACF FORM.
    I have multiple ACF groups and multiple CPT, do you know if i can manage all them in an acf/save_post function ? Should identify ACF group slug ?
    Because in documentation there is only if( isset($_POST[‘acf’]) ) , shouldn’t it be if( isset($_POST[‘my_acf_group_slug_or_id’]) ) ?

    I need to get form values “DO SOMETHING different” depending on which CPT is created.

    As i have a lot of taxonomy list, will it be a simple way to get the name of the selected values ?

    Thanks

  • acf/save_post is called with the post ID of the post being saved. For more information on this https://www.advancedcustomfields.com/resources/acf-save_post/.

    You can get the post type like this

    
    $post_type = get_post_type($post_id);
    if ($post_type == 'your-custom-post-type-slug') {
      // do something for this post type
    }
    

    All field in all groups included in the form are submitted and all are in $_POST[‘acf’] and do not include any additional information that tells you what group they are in.

    I’m not sure what you mean in your reference to taxonomies.

  • Thanks a lot
    So if I understand as I have 3cpt for 3 different forms , I will have 3 « if » where I will have $post[acf]…

    I am surprised that to parse the content of $post[acf] I have to specify in harcode the if of each field, I toought it could be dynamic.
    I have a lot of taxonomies fields to get so many for each loop.

  • If you are doing something before ACF, the priority of our filter is <10 then yes. You must look at each field key. ACF does not include information about a fields group when fields are added to the page. This can be seen in the admin as well. ACF data is related to the post, not the field group.

  • Sorry I don’t really understand…
    I use twilio core to send sms so in acf post I use the sms function to send it.

    I must retrieve all the values submited in the form and affect to the sms body variable before to execute the function. Problem is not the sms. It would be the same if It was an email.

    I must get all values from $post[acf] and put them in $mybodymessage.
    Doing this is the first difficulty.
    The second difficulty is I don’t understand how can I now if $post[acf] contains data from my formA or my formB
    Hope it helps …
    Thanks

  • If I understand well,

    when you are in the function hooked by :

    add_filter('acf/save_post' , 'fn_save_post', 10, 1 );

    your post and acf values are already saved, so you can get them by using :

    $your_acf_field_key = get_field('your_acf_field_key', $post_id);

    then, you can deal with all variables to send SMS or whatever

  • hello,

    I have a form1 on page1 and a form2 on page2, i need to get the value submit by the forms, no matter for me if it is after on before the post is created in database.
    For now this is what i do but
    1. Don’t know if it’s the good hook
    2. Like in docs, i have hardcoded (field_5c33260621785) the fields to retrieve (is it no possible dynamically ?)
    3. In this function, how can i know if $_POST[‘acf’] comes from FORM1 or FORM2 ?
    4. THnaksss a lot !!!

    function my_acf_save_post( $post_id ) {
     	$fields = false;
      	if( isset($_POST['acf']) )
    	{
    // get taxonomy sent my form on PAGE A	
    $zones = $_POST['acf']['field_5c33260621785'];
             foreach ($zones as $z) {
             $term = get_term( $z, 'zones_de_marche' );
             $name .= $term->name ."\r\n"; 
             }
    
    	}
     
    $args = array( 
        'number_to' => '+33111111',
        'message' => $name
    ); 
    twl_send_sms( $args );
     
                     }
    
    add_action('acf/save_post', 'my_acf_save_post', 20);
Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.