zaus / forms-3rdparty-integration

Wordpress Plugin - Forms 3rdparty Integration - a plugin to help integrate 3rdparty services with common WP Forms plugins like Contact Form 7 and Gravity Forms
http://wordpress.org/plugins/forms-3rdparty-integration/
47 stars 14 forks source link

Add special service separator for indexed nesting #43

Closed zaus closed 8 years ago

zaus commented 9 years ago

See https://github.com/zaus/forms-3rdparty-xpost/issues/11

Specifically, here add a case for [%] that will use the following function to prepare the destination field (key) for indexed nesting by the XPost plugin.

function placeholder_separator($post) {
    $new = array(); // add results to new so we don't pollute the enumerator
    // find the arrays and reformat keys with index
    foreach($post as $f => $v) {
        if(is_array($v)) {
            // for each item in the submission array,
            // get its numerical index and replace the
            // placeholder in the destination field

            foreach($v as $i => $p) {
                $k = str_replace('%i', $i, $f);
                $new[$k] = $p;
            }

            unset($post[$f]); // now remove original, since we need to reattach under a different key
        }
    }
    return array_merge($post, $new);
}