最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Contact Form 7 select dynamic value from server - Stack Overflow

programmeradmin0浏览0评论

I am bound to using Contact Form 7 for wordpress. I would like to use a select drop-down, however the available options should not be statically but rather dynamically loaded from the server (to be precise a csv file). I thought about using a filter (something like 'wpcf7_form_tag') but wasn't quite able to make it work yet.

Does anyone have an idea how to tackle that challenge?

I am bound to using Contact Form 7 for wordpress. I would like to use a select drop-down, however the available options should not be statically but rather dynamically loaded from the server (to be precise a csv file). I thought about using a filter (something like 'wpcf7_form_tag') but wasn't quite able to make it work yet.

Does anyone have an idea how to tackle that challenge?

Share Improve this question asked Feb 2 at 8:17 LukiolioLukiolio 93 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

you can use jQuery for this approach.

 $.post("csv.asp", function(data, status){
      //split csv with comma
      $data = data.split(",");
      //empty select - use your page select class
      $("select.contact-form-7").html('');
      for($i=0;$i<$data.length;$i++){
         $option = "<option>"+$data[$i]+"</option>";
         $("select.contact-form-7").append($option);
      }
 });

You can try the Data Source for contact form 7 ( https://wordpress./plugins/cf7-data-source/ ). It includes a pair of additional controls, Recordsed, to get the data from different data sources, like a database, a CSV file, a JSON structure, and other alternatives, and the RecordSet Field Link control that allows you to connect the form fields, like the DropDown field with the RecordSet to populate the first one with the information obtained from the data source.

You can find multiple functional examples in the following link:

https://cf7-datasource.dwbooster/examples

发布评论

评论列表(0)

  1. 暂无评论