• Resolved Kimantis_Creative_Group

    (@kimantis_creative_group)


    Hello, the map field is not being sanitized in the email – any trick to do it?

    Address: {\”address\”:\”9 Chemin de l\’Aboiteau, Cap-Pelé, NB E4N 1P2, Canada\”,\”lat\”:46.2231566,\”lng\”:-64.3064406,\”zoom\”:19,\”place_id\”:\”ChIJvYFWJcWcoEwRxwQkPG0wJMU\”,\”street_number\”:\”95\”,\”street_name\”:\”Chemin de l\’Aboiteau\”,\”city\”:\”Cap-Pelé\”,\”state\”:\”Nouveau-Brunswick\”,\”state_short\”:\”NB\”,\”post_code\”:\”E4N 1P2\”,\”country\”:\”Canada\”,\”country_short\”:\”CA\”}

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello!

    Thanks for the feedback! Sorry for the late answer, I’m currently really busy with the next patch.

    In fact, the Google Map return value isn’t formatted in Dynamic Forms. I added it to the to-do list in the Trello Board: https://trello.com/c/Nur96pp8/127-dynamic-forms-google-map-field-format

    Meanwhile, you can format the data the way you want, using the following code:

    
    add_filter('acfe/form/format_value/type=google_map', 'my_acfe_format_google_map', 10, 4);
    function my_acfe_format_google_map($value, $_value, $post_id, $field){
        
        if(is_string($value)){
            
            $value = json_decode(wp_unslash($value), true);
            
        }
        
        $value = acf_get_array($value);
        
        $address = acf_maybe_get($value, 'address');
        
        return $address;
        
    }
    

    Hope it helps!

    Regards.

    Thread Starter Kimantis_Creative_Group

    (@kimantis_creative_group)

    Thank you so much! I was able to customize this perfectly! ACF extended is a must! Keep rocking my friend!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    I’m glad to hear that it now works as you wanted! If you enjoy ACF Extended, feel free to submit a review, it always help and it’s much appreciated ??

    Have a nice day!

    Regards.

    Thread Starter Kimantis_Creative_Group

    (@kimantis_creative_group)

    Hey hwk-fr,
    I just send a little something via Ko-fi! Enjoy your coffee!
    It’s me again. I’ve been having some issues with the custom hook to send an email.

    I am only trying to do a custom action if order_plan = yes { } do something + update field else return.

    My wp email logs doesn’t even show anything when I use the hooks.. any help would be appreciated.

    add_action('acfe/form/submit/request-map-info', 'my_form_custom_action', 10, 2);
    function my_form_custom_action($form, $post_id){
    
        $my_post_field = get_field('order_plan', $post_id);
        
        if($my_field === 'no'){
              
            return;
            
        } elseif ($my_field === 'yes') {
           
        $email = array('email');
        $body_text = get_field('add_full_address', $post_id );
    
        $to = $email;
        $headers = array('From: some name '.$email.' <noreply@'.$_SERVER['HTTP_HOST'].'>');
        $subject = 'Testing Email 2020 ' . get_field('add_new_address', $post_id) . ' ' . get_field('client_name', $post_id);
        $message = $body_text;
    
        wp_mail($to, $subject, $message, $headers ); 
            
        }
        
        );
        
    }
                      
                     
    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the donation, that’s very kind ??

    There are several problems with your code:

    1. You make a condition on a variable that isn’t set if($my_field === 'no'). $my_field isn’t set at this time.

    2. Your code $my_post_field = get_field('order_plan', $post_id); retrieve the data from the current page that display the form. I don’t think that’s what you’re looking for. If you want to retrieve actual form user input just use: $my_post_field = get_field('order_plan'); (without the $post_id). You’ll find code example in the “Advanced tab”.

    3. Your e-mail headers look wrong, as you’ve set the “From $email”, but $email = array('email'); which doesn’t make sense.

    In order to debug your code, I would advise you to code and test step by step.

    Here is an example:

    
    add_action('acfe/form/submit/request-map-info', 'my_form_custom_action', 10, 2);
    function my_form_custom_action($form, $post_id){
    
        // Retrieve "order plan" user input
        $order_plan = get_field('order_plan');
        
        if($order_plan === 'yes'){
            
            echo 'yes';
            die;
            
        }elseif($order_plan === 'no'){
    
            echo 'no';
            die;
            
        }
        
    }
    

    Note that I added die; after writing a debug message, to stop all other execution. This is basically a code to test your condition first. You can also use acf_log('yes') to log data in the debug.log file instead of writing a text.

    Once your condition work as expected, you can go ahead and write + debug your wp_mail() call. Again, starts by writing a custom wp_mail() function, without variable. Then once the mail is sent, set your variables etc…

    Hope it helps!

    Regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘ACF Dynamic form – Map Field’ is closed to new replies.