Skip to content

Add special service separator for indexed nesting #43

@zaus

Description

@zaus

See zaus/forms-3rdparty-xpost#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);
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions