• Resolved nootkan

    (@nootkan)


    Hope this is the right forum for this question. I have been trying to use a function added into my child theme to try and block url from being posted in my contact form.

    I’m not that well versed with php so thought I would seek help from someone who is.

    Here is the code:

    function custom_textarea_validation_filter($result, $tag) {
       $type = $tag[‘type’];
       $name = $tag[‘name’];
       //here textarea type name is ‘message’
       if($name == ‘your-message’) {
          $value = $_POST[$name];
          if (preg_match(‘/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i’, $value)){
          $result->invalidate( $tag, “Avoid URLs & Links” );
          }
       }
    return $result;
    }
    add_filter(‘wpcf7_validate_textarea’,’custom_textarea_validation_filter’, 10, 2);
    add_filter(‘wpcf7_validate_textarea*’, ‘custom_textarea_validation_filter’, 10, 2);

    And here is the error message:

    [10-Aug-2020 18:04:32 UTC] PHP Parse error: syntax error, unexpected ‘?’ in /home/mywebsite/public_html/wp-content/themes/nikkon-child/functions.php on line 34

    Tried using double question marks and another regex solution but still get the same errors. Any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter nootkan

    (@nootkan)

    Forgot to add the server info:

    cPanel Version 88.0 (build 13)
    Apache Version 2.4.46
    PHP Version 7.2.33
    MySQL Version 5.7.31
    Architecture x86_64
    Perl Version 5.16.3
    Kernel Version 3.10.0-1127.18.2.el7.x86_64

    Just experimented with this regex

    if ( '/www\.|http:|https:\/\/[a-z0-9_]+([\-\.]{1}[a-z_0-9]+)*\.[_a-z]{2,5}'.'((:[0-9]{1,5})?\/.*)?$/i' $value)){
    $result->invalidate( $tag, “Avoid URLs & Links” );

    and got PHP Parse error: syntax error, unexpected ‘$value’ (T_VARIABLE)

    Will keep digging but some help would be greatly appreciated.

    Thread Starter nootkan

    (@nootkan)

    Not sure why this was moved here because it has nothing to do with the Nikkon theme so you can remove it if you like.

    Thread Starter nootkan

    (@nootkan)

    If you’re interested my solution is found here:
    Contact 7

    • This reply was modified 4 years, 3 months ago by nootkan.
    • This reply was modified 4 years, 3 months ago by nootkan.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Child Theme Function Code Error Question’ is closed to new replies.