• This works great: (from cfdbplugin.com)
    “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.”

    However — to limit data trolling — must use exact match — except let it be case insensitive. For example someone may have entered last-name as adams, Adams, or ADAMS. Please, anyone have a quick answer? Thank you!

    https://wordpress.org/plugins/contact-form-7-to-database-extension/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter wilderbee

    (@wilderbee)

    Stumbled upon something called strtolower. Works — except when corresponding input field is left empty returns big error message “Warning: strtolower() expects parameter 1 to be string, array given in …” No harm to functionality, just ugly and scary to users. Is there a way to avoid/suppress that message — or another method to do an exact match that is not case sensitive?

    ‘<form action=”” method=”POST”>Zip Code: <input type=”text” name=”zip5″ /> Last Name: <input type=”text” name=”last-name” /> First Name: <input type=”text” name=”first-m” /> <input type=”hidden” name=”x” value=”1″/> <input type=”submit” /> </form>’

    ‘[cfdb-datatable form=”my-form2″ show=”date,last-name,first-m,city,state,zip5″ filter=”zip5=$_POST(zip5)&&strtolower(last-name)=strtolower($_POST(last-name))&&first-m~~/$_POST(first-m).*/i&&intval(1)=$_POST(x)” ]’

    Thread Starter wilderbee

    (@wilderbee)

    Please, any ideas, anyone, how to to search by exact match but not be case sensitive? Or how to suppress the above error message would do. Or maybe how to force a letter in the input field when the user does not, to prevent the empty-field error message? Or maybe how to require that field (or rather two fields at the same time) have something in it before a search will run? Any workarounds? Have come a long way but always there is more, PHP/Java is yet on my horizon. Thank you!

    Plugin Author Michael Simpson

    (@msimpson)

    You can use the regex without the “.*”s in it:

    filter="zip5~~/^$_POST(zip5)$/i&&last-name~~/^$_POST(last-name)$/i&&first-m~~/^$_POST(first-m)$/i&&intval(1)=$_POST(x)"

    But you you have to fill in values for all the fields. If you leave a field blank, it searches for a blank.

    That will give you case-insensitive but if someone puts “.*” in those fields, then is shows everything.

    Plugin Author Michael Simpson

    (@msimpson)

    You can also create a custom filter function in PHP to enforce the logic you want exactly.

    This code might do what you want.

    require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBPermittedFunctions.php');
    
    function match_search_fields($entry) {
        $form_fields = array('zip5', 'last-name', 'first-m');
        $num_fields_filled_out = 0;
    
        foreach ($form_fields as $field) {
            if (isset($_REQUEST[$field]) && $_REQUEST[$field]) {
                if (strtolower($_REQUEST[$field]) != strtolower($entry[$field])) {
                    return false;
                }
                $num_fields_filled_out++;
            }
        }
    
        if (! $num_fields_filled_out) {
            // Don't match if nothing in the form was filled out
            return false;
        }
    
        return true;
    }
    
    cfdb_register_function('match_search_fields');

    Shortcode is:
    [cfdb-datatable form="my-form2" show="date,last-name,first-m,city,state,zip5" filter="match_search_fields()" ]

    And you don’t need the “x” field in the search form.

    Thread Starter wilderbee

    (@wilderbee)

    Thank you! That is a nice chunk of help. Cannot test until next week, going live with what we’ve got then patch it up on the other side after all else shakes out. Many thanks.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘filter for exact name but case insensitive’ is closed to new replies.