• Resolved martinushm

    (@martinushm)


    Hi there,

    Great plugin man! Helps me out a lot.

    Is it possible to get the value from a tag after the pipe (|)? This is of course what happens when CF7 sends an email, but with this plugin the value before the pipe gets transferred.

    For example I have a question in my form with the checkbox options ‘Yes’ and ‘No’ and the tag looks like this:

    [checkbox* type id:type default:2 use_label_element exclusive “Yes.|Custom” “No|Standard”]

    I would like to use the value after the pipe (‘Custom’ in this example) instead of the value before it (‘Yes’ in this example).

    Could you tell me how to do this?

    Thanks a lot!

    Martin

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter martinushm

    (@martinushm)

    Here’s CF7’s documentation on pipes: https://contactform7.com/selectable-recipient-with-pipes/

    Plugin Author Mário Valney

    (@mariovalney)

    Hi @martinushm!

    This plugin get the data in $_POST variable wich means we get the data submited by form. Using pipe values make CF7 parse this data before send mail.

    I will take a note about this as feature request to the next version. Thanks for sharing.

    For now, I guess you can try to parse the data by yourself using this code (it’s the same code CF7 use to parse data before sending mail):

    
    function martinushm_ctz_get_data_from_contact_form( $data, $contact_form ) {
        $tags = (array) $contact_form->scan_form_tags();
    
        foreach ( $tags as $tag ) {
            if ( empty( $tag->name ) ) continue;
    
            $pipes = $tag->pipes;
    
            $value = isset( $_POST[$tag->name] ) ? $_POST[$tag->name] : '';
            if ( WPCF7_USE_PIPE && $pipes instanceof WPCF7_Pipes && ! $pipes->zero() ) {
                if ( is_array( $value) ) {
                    $new_value = array();
    
                    foreach ( $value as $v ) {
                        $new_value[] = $pipes->do_pipe( wp_unslash( $v ) );
                    }
    
                    $value = $new_value;
                } else {
                    $value = $pipes->do_pipe( wp_unslash( $value ) );
                }
    
                $data[$tag->name] = $value;
            }
        }
    
        return $data;
    }
    
    add_filter( 'ctz_get_data_from_contact_form', 'martinushm_ctz_get_data_from_contact_form', 10, 2 );
    

    Let me know if it works.

    Thanks for using our plugin and a review would be would be aprecciated.

    Thread Starter martinushm

    (@martinushm)

    Hey Mário!

    Thanks for the quick reply. That works! Almost got everything working now ??

    Would definitely be great to add as a functionality in the future to the plugin.

    One last thing that I would like to send to Zapier is the date when the form was posted. Do you know how I can add this? It’s in the metadata (for example I can see this in Flamingo, a database add-on for CF7 by the same developer), but it does not show up in the data that will be sent to Zapier.

    Thanks again!

    P.S. Just added a 5-star review

    Thread Starter martinushm

    (@martinushm)

    I found this..

    add_filter( 'ctz_get_data_from_contact_form', 'martinushm_add_time_to_form', 10, 2 );
    
    function martinushm_add_time_to_form( $data, $contact_form ) {
        $data['submited_at'] = date( 'Y-m-d H:i:s' );
    
        return $data;
    }

    But this is giving the time in UTC, not taking into consideration the time of my WordPress..

    Plugin Author Mário Valney

    (@mariovalney)

    Thanks for the 5-star review. <3

    To get the current time of WordPress you can use current_time:

    $data['submited_at'] = current_time( 'Y-m-d H:i:s' );

    Thread Starter martinushm

    (@martinushm)

    Awesome!! Thanks Mário

    Plugin Author Mário Valney

    (@mariovalney)

    Hey! How are you?

    Version 1.2 will support CF7 Pipe. Please update ??

    Thread Starter martinushm

    (@martinushm)

    Cheers Mário!!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Get value AFTER a pipe’ is closed to new replies.