Support » Plugin: Contact Form DB » [Contact Form 7 to Database] How do I setup the search to work with [cfdb-html]?

  • I like the way search works with [cfdb-datatable], but I don’t understand how to get it to work with [cfdb-html]?
    If I add ‘search=”yes”‘ into [cfdb-html] it searches on “yes”. How do I use a search box and dynamically change “yes” to the given search term?
    I need to use [cfdb-html] instead of [cfdb-datatable] to allow me to format the output and to enable be to make a url called from the database active.
    Initially I expected the search box to be added dynamically by declaring search=”yes”, not for it to act as a search for the word “yes”.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    The “search” and “filter” fields apply to filtering the results returned by the database when the page is loaded. Once you have those results on the page (or all results if you don’t use them) then the only way to filter them in the page itself is to use [cfdb-datatable] which gives you the search box (Example page). That search box comes from the external DataTables javascript library and so only appears for that shortcode.

    The “search” field is intended to filter on the server side in the same way that the datatable search box works in the page. Really, its just a simpler form of “filter”.

    The “yes” example is misleading, I will change that.

    Thinking about what you want to achieve: conceivably you could open a table tag (give it an id), put in [cfdb-html] inside it where each entry is one table row with one table cell containing your formatted contents, then add the datatable script to wrap your table as a DataTable. That would then give you the search box.

    To make your table a datatable, add this (wrap in a script tag)

    jQuery(document).ready(function() {
           jQuery('#YOUR_TABLE_ID').dataTable({
              "bJQueryUI": true, "aaSorting": [] })
       });

    I wonder if I should create a shortcode for this….

    Thread Starter Andy

    (@routetoweb)

    Thanks for your reply.
    I sort of archived what I was after and getting the url from the database to become a link with the following:

    jQuery(window).load(function(){
    	jQuery("td").each(function(i){
    		if(jQuery(this).attr("title")=="Website"){
    			var strTD = jQuery("td").eq(i).text();
    			var strReplacingTD = '<a href="http:\/\/'+strTD+'">'+strTD+'</a>';
    		jQuery("td").eq(i).replaceWith("<td><div>"+strReplacingTD+"</div></td>");
    		};
    	});
    });

    Note “Website” is the name of the ‘data field’.

    I’m not getting the page formatting that I would like to have achieved by using HTML, but the URLs from the database are now links and the data remains searchable both of which are of a higher priority.
    I hope the code is of use to others.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Contact Form 7 to Database] How do I setup the search to work with [cfdb-html]?’ is closed to new replies.