Hello @gatestar
Thank you very much for using our plugin. In this case, you don’t want to fill the field with the values stored in the database table. You want to select the value from the existing dropdown field. A possible alternative is the use of callbacks.
I’ll try to describe the process with an example.
Assuming I have the dropdown field posts with some posts ids as their choices:
[select posts "--SELECT--" "22" "23"]Now, I want to read the list of published posts from the database and select the first choice that matches any of the posts read from the database. I insert the record-set tag to read the posts ids from the database and include the callback argument:
[cf7-recordset id="posts-data" type="post" attributes="ID" condition="post_type="post" AND post_status="publish"" callback="select_option"]Finally, I implement the callback function in the form content:
<script>
function select_option(records) {
var e;
for(var i in records){
e = jQuery('[name="posts"] option[value="'+records[i]['ID']+'"]');
if( e.length ){ e.prop('selected', true); return;}
}
}
</script>The complete form structure would be:
<label> Posts Ids
[select posts "--SELECT--" "22" "23"] </label>
[cf7-recordset id="posts-data" type="post" attributes="ID" condition="post_type="post" AND post_status="publish"" callback="select_option"]
<script>
function select_option(records) {
var e;
for(var i in records){
e = jQuery('[name="posts"] option[value="'+records[i]['ID']+'"]');
if( e.length ){ e.prop('selected', true); return;}
}
}
</script>
Now, you only should modify your record-set tag to include the callback argument and implement the callback function adjusted to your project needs.
Best regards.
