*/
public function modelAction ($actionData = false)
{
- if( isset( $_REQUST['table'] ) ){
-
+ global $wpdb;
+
+ if( isset( $_REQUEST['table'] ) ){
+ $fields = $_REQUEST['fields'];
+ $table = filter_var($_REQUEST['table'], FILTER_SANITIZE_STRING);
+ $sql = "SELECT $fields image FROM $table where title like '%pack%'";
+ $packages = $wpdb->get_results($sql);
+ foreach($packages as $package){
+ $searchData[] = [
+ $package->title => $package->image
+ ];
+ }
+ }else{
+ $table = null;
}
- $data = "test";
+
$return = array(
- 'data' => $data , // Where our events list will go
+ 'data' => $fields,
+ 'searchData' => $searchData // Where our events list will go
);
header('Content-type:application/json;charset=utf-8', true);
let data = {
action : 'glm_members_admin_ajax',
glm_action : 'glmTextSearch',
- table : '{$widgetField.table}'
+ table : '{$widgetField.table}',
+ fields : '{", "|implode:$widgetField.fields}'
}
- $.ajax({
- type: 'POST',
- url: '{$ajaxUrl}',
- data: data,
- success: function(response) {
- console.log(response)
- $('input.earch-autocomplete').autocomplete({
- data: {
- "Apple": null,
- "Microsoft": null,
- "Google": 'https://placehold.it/250x250'
- }, // The max amount of results that can be shown at once. Default: Infinity.
- });
- }
- });
+ $(function() {
+ $.ajax({
+ type: 'POST',
+ url: '{$ajaxUrl}',
+ data: data,
+ success: function(response) {
+ let searchDropdown = {};
+
+ for(let i = 0;i < response.searchData.length;i++){
+ let searchTitle = Object.keys(response.searchData[i]);
+ let image = (response.searchData[i][searchTitle]) ? response.searchData[i][searchTitle] : null;
+ searchDropdown[searchTitle] = null;
+ }
+ console.log(searchDropdown)
+ $('input.search-autocomplete').autocomplete({
+ minLength: 3,
+ data: searchDropdown // The max amount of results that can be shown at once. Default: Infinity.
+ });
+ }
+ });
+ })
});
</script>
\ No newline at end of file