Creating a form to search the database
What to create a form to that can be used to search your form entries? Follow this example:
1 2 3 4 5
<form action="" method="POST"> First Name: <input type="text" name="fname" /> Last Name: <input type="text" name="lname" /> <input type="submit" /> </form>
[cfdb-datatable form="Contact Form" filter="fname~~/.*$_POST(fname).*/i&&lname~~/.*$_POST(lname).*/i"]
In the form, put whatever fields you wish to search on. You can name these form fields by any name.
Use a short code with the filter attribute. Here we use filter variable substitution. $_POST(fname) and $_POST(lname) will be substituted with the values of the form post.
For the filter in the short code, string together regular expressions of the form
database_form_field_name~~/.*$_POST(posted_field_name).*/i. The “.*” at the front and end of the regex allow the user to just type in part of a word and find a match. The “i” makes it case-insensitive.
Chain all the regex’s together with logical AND (&&). If a user leaves an entry blank in the search form like fname in the example above then
fname~~/.*$_POST(fname).*/i will become
fname~~/.*.*/i after substituting an empty string. This regex will match all entries. The effect is as if this contraint did not exist. So this means that a user can fill in only those elements on the search form that he wants to constrain. Those that are not filled out are effectively unconstrained.