Hi Tim
We are working on an update to Views that would make this a little easier, but for now let me explain what's currently involved.
You can add a generic field to your Form and add the persist: 1 option to save the field to the database when submitted.
In the screenshot you can see me adding a generic multi-select field ("selections") where I am using a View to generate the dropdown options.
That inserts markup like so:
[cred_generic_field field='selections' type='multiselect' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[],
"options":[ [wpv-view name="options-view"] ],
"persist":1
}
[/cred_generic_field]
Note how I manually added the persist option to save this field.
Now, the problem is that the output of Views includes wrapper markup which is required to make things like pagination and front-end filtering work.
We don't need any of that, we just need a View which generates output in the required JSON format.
That format needs to look like this:
"options":[
{"value":"1","label":"One"},
{"value":"2","label":"Two"},
{"value":"3","label":"Three"}
]
We are working on adding a "clean" output format for Views which will facilitate this, but in the meantime the only solution is to use a regex to strip out the surrounding wrapper.
So, having created a View to generate your options in the format shown above, you would need to add the following to your theme's functions.php file to "clean" the View output:
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'tssupp_clean_view_output', 5, 2 );
function tssupp_clean_view_output( $out, $id ) {
if ( $id == '375' ) { // Edit View ID
$start = strpos( $out, '<!-- wpv-loop-start -->' );
if (
$start !== false
&& strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
) {
$start = $start + strlen( '<!-- wpv-loop-start -->' );
$out = substr( $out , $start );
$end = strrpos( $out, '<!-- wpv-loop-end -->' );
$out = substr( $out, 0, $end );
}
}
return $out;
}