Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author moshensky

    (@moshensky)

    Nice catch!
    I’ll add this during next week and notify you in this theme.

    Thread Starter arabtornado

    (@arabtornado)

    Thank so much ??

    Plugin Author moshensky

    (@moshensky)

    Good night @arabtornado
    I’ve added this feature.
    But looks like it’s not so stable on CF7 side. I’ve tried and it works on ‘select’ and ‘hidden’, but it not works on ‘checkbox’ for me (I’ve no idea about the reason).
    Anyway, I hope it covers your request. Feel free to ping me if something goes wrong.

    Thread Starter arabtornado

    (@arabtornado)

    @moshensky Thank you for the update, But unfortuinatly i discovered a major bug on that update so i suggest to unpublish that update till it got fixed.
    If a placeholder is used on a text field (maybe also on other types of fields) that cause the placeholder text to be sent to the google sheet instead of the user input value.

    I noticed that you are using a way to get the posted input fields that may uses Regex which im not sure that i understand but i guess this might be the reason for that issue.
    Honestly i belive that there are a cleaner ways to do that which mentioned here
    https://stackoverflow.com/questions/42807833/how-to-capture-post-data-with-contact-form7

    and i think that CF7 by default use the field value after pipe so it should not be a proplem and to get the value before pipe you need to [_raw_{field name}]
    https://contactform7.com/selectable-recipient-with-pipes/

    Plugin Author moshensky

    (@moshensky)

    I’ll check placeholders in the evening.

    I didn’t get CF7 explanation about [_raw_{field name}], because I didn’t found it. On before send hook, that I use nothing looks like that. Anyway at the moment I’m far away from WordPress and PHP, so maybe I don’t see some best practices. Only way, that I found – to use $_POST data and split form by regex.

    I’ll let you know if any update/patch.

    Thread Starter arabtornado

    (@arabtornado)

    Hi @moshensky
    actually what i meant is that you can use the builtin CF7 classes or filters to get the data, for instance using wpcf7_posted_data filter you can capture the posted data. the code example below can capture the posted data in a form of an array with the real value even if the pipe was used and then you can do whatever you want with that data, on my exaple i posted it to https://webhook.site using cURl, and the posted data includes also the form id.

    add_filter( 'wpcf7_posted_data', function( $data ) {
    $data_string = json_encode($data);                                                                                   
    $ch = curl_init('https://webhook.site/d15e1662-a1ca-4fe5-beff-13f8c7350c91');                                                                      
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($data_string))                                                                       
    );                                                                                                                   
    
    $result = curl_exec($ch);
    
      return $data;
    } ); 
    
    • This reply was modified 4 years, 9 months ago by arabtornado.
    Thread Starter arabtornado

    (@arabtornado)

    Or maybe to avoid filters priority issues/conflict with other plugins it might be better to use WPCF7_Submission class instead like the following, and that method too solves the pipe issues by itself

    
    add_action( 'wpcf7_before_send_mail', 'your_wpcf7_function' );
    function your_wpcf7_function( $contact_form ) {
    $id = $contact_form->id;
    $submission = WPCF7_Submission::get_instance();
    
    if ( $submission ) {
        $posted_data = $submission->get_posted_data();
    }
    
     $data_string = json_encode($title);
    
     $ch = curl_init('https://webhook.site/d15e1662-a1ca-4fe5-beff-13f8c7350c91');
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    		 'Content-Type: application/json',
    		 'Content-Length: ' . strlen($data_string))
     );
    
     $result = curl_exec($ch);
    }
    
    Plugin Author moshensky

    (@moshensky)

    Something wrong with this pipes feature (it affects placeholders too).
    I did small rollback, so this theme feature isn’t working now.

    I hope I’ll fix it on weekends (really busy). If you want to help – please feel free to open PR to https://github.com/moshenskyDV/CF7-spreadsheets

    Thread Starter arabtornado

    (@arabtornado)

    Thanks @moshensky , i would love to help but unfortuinatly i still not good enough in PHP and regex to be able to read and fully understand your code.
    but by looking on your code i became curious about the reason you tried to get the fields from the post_meta and filter it using Regex instead of just capture the posted data in an array using WPCF7_Submission class as shown above.

    Plugin Author moshensky

    (@moshensky)

    @arabtornado thanks a lot for idea. Really with WPCF7_Submission much easier than with $_POST. I’ve done with this feature.

    PS: do you want to try new version before I landed it to all users?
    I found that wordpress SVN repository is able to store a couple of stable/unstable versions. You can find version 2.2.4 by this link (on the bottom).
    I’ll wait for your review for a week, if everything OK – I’ll push this version as stable to all users. Thanks a lot for solution!

    Thread Starter arabtornado

    (@arabtornado)

    @moshensky Thanks allot, seems to be working very good for me so far and the pipe and placeholder issues are no longer exist now.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Send the field value to the sheet instead of the label’ is closed to new replies.