• Resolved jirkad

    (@jirkad)


    Hello,

    I created a custom form tag, which returns ACF file URL:

    <?php 
     
    add_action('wpcf7_init', 'custom_acf_file_url_form_tag');
     
    function custom_acf_file_url_form_tag(){
        wpcf7_add_form_tag('acf_file_url', 'custom_acf_file_url_form_tag_handler');
    }
     
    function custom_acf_file_url_form_tag_handler($tag){
        $acf_field = get_field('produkt_schema', $post->ID);
        $url = $acf_field['url'];
     
        //create html and return
     
        $html = '<a href="'.$url.'" target="_blank">Download</a>';
     
        return $html;
     
    }
    
    ?>
    

    Now I need to send an e-mail to the customer with the URL. When I add [acf_file_url] to the e-mail body, it return only [acf_file_url], not actually $html;..

    Any ideas on how to make it work?

    Thanks, George

Viewing 6 replies - 1 through 6 (of 6 total)
  • could you try adding as the first line after
    function custom_acf_file_url_form_tag_handler($tag){

    the code to get the $post global?
    global $post;

    (sorry untested)

    Thread Starter jirkad

    (@jirkad)

    I tried, but unfortunately it doesn’t work ??

    <?php 
     
    add_action('wpcf7_init', 'custom_acf_file_url_form_tag');
     
    function custom_acf_file_url_form_tag(){
        wpcf7_add_form_tag('acf_file_url', 'custom_acf_file_url_form_tag_handler');
    }
     
    function custom_acf_file_url_form_tag_handler($tag){
        global $post;
        $acf_field = get_field('produkt_schema', $post->ID);
        $url = $acf_field['url'];
     
        //create html and return
     
        $html = '<a href="'.$url.'" target="_blank">Stáhnout produktovy list</a>';
     
        return $html;
        
    }
    
    ?>

    you are able to get the post id in this way?

    add_action('wpcf7_init', 'custom_acf_file_url_form_tag');
    
    function custom_acf_file_url_form_tag(){
    	wpcf7_add_form_tag('acf_file_url', 'custom_acf_file_url_form_tag_handler');
    }
    
    function custom_acf_file_url_form_tag_handler($tag){
    	global $post;
    	return $post->ID;
    }
    Thread Starter jirkad

    (@jirkad)

    Yes, it returns the post ID number. But unfortunately, it doesn’t work with the ACF field.

    I found this on ACF forum:

    ACF only stores the ID of the field for the meta_key/meta_value. CF7 (or the add on your using) is directly accessing the meta value and not going through ACF to get the value.

    But I am not able to make it works :/

    if you can get the post id probably it’s related to acf, I used it a lot in the past but now I don’t even have an installation, so it’shard for me to help you!

    this will print the content of the product schema if any for this post id

    function custom_acf_file_url_form_tag_handler($tag){
    	return implode(", ",  get_field('produkt_schema'));
    }
    Thread Starter jirkad

    (@jirkad)

    Hi Erik,

    I just figured it out with the external plugin Contact Form 7 – Dynamic Text Extension and dynamichidden field. Inside this field, I put my own shortcode which returns ACF field URL.

    Thank you for your time,

    George

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom Form tag (ACF file URL) in the e-mail message’ is closed to new replies.