admin管理员组

文章数量:1310012

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

本文标签: phpContact Form 7 select dynamic value from serverStack Overflow