• I am trying to filter user input in contact forms created using contact form 7 before saving them into the database.

    I used the documentation found @
    https://cfdbplugin.com/?page_id=1073 ( @michael Simpson)
    Here is my filter function

    require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBPermittedFunctions.php');
    
    function cfdb_onlytext($input) {
      if(preg_match('/^[a-zA-Z .\-]+$/i', $input)) {
         return $input;
       }else {
         return "Your name is invalid and must contain only letters" ;
       }
    }
    
    cfdb_register_function('cfdb_onlytext');

    My contact form code is [contact-form-7 id="4" title="Contact form 1"]

    <p>Your Name (required)<br />
        [text* your-name] </p>
    
    <p>Your Email (required)<br />
        [email* your-email] </p>
    
    <p>Subject<br />
        [text your-subject] </p>
    
    <p>Your Message<br />
        [textarea your-message] </p>
    
    <p>[submit "Send"]</p>

    Consequently this is the short code should be

    [cfdb-table form="Contact form 1" filter=”cfdb_onlytext(your-name)” ]

    The contact form is placed in a page “Sample Page”

    This is a sample page
    
    [contact-form-7 id="4" title="Contact form 1"]

    I want to filter the “Your Name” user input and store it in the database only if the input is valid .In case the input is not valid then “Your name is invalid and must contain only letters” message must be shown in the contact form.

    Where should i place the short code (i don’t want to display anything to the user).If i paste it in the page then the table is shown in the contact form

    Thanks for helping me out

    Regards

  • The topic ‘Using ContactformDB filters with contact form 7’ is closed to new replies.