• Resolved fesenkoe

    (@fesenkoe)


    Hi! There is some problem when somebody writes a message like this “sometext\n\n”. So I have invalid JSON format {“count” : 1, “stack” : “sometext\n\n”}. I have tried to apply add_filter(‘qs_cf7_api_before_sent_to_api’, ‘callback’) and change $record, but returns nothing. Can you suggest a resolve?
    Thanks!)

    • This topic was modified 4 years, 8 months ago by fesenkoe.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter fesenkoe

    (@fesenkoe)

    I’ve resolved this problem

    add_filter( ‘cf7api_create_record’, ‘prepare_data_before_sent_to_api’, 10, 5);

    function prepare_data_before_sent_to_api($data) {
    try {
    if (isset($data[‘fields’]) && is_string($data[‘fields’])) {
    $data[‘fields’] = preg_replace(“/[\r\n]+/”, “\\n”, $data[‘fields’]);
    }
    } catch (Exception $e) {}

    return $data;
    }

    Plugin Author Kenny Meyer

    (@kennymeyer)

    @fesenkoe awesome. Feel free to submit a PR, and I’ll review it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pass invalid JSON format to API’ is closed to new replies.