Support

Account

Home Forums Backend Issues (wp-admin) Validation URL domain

Solved

Validation URL domain

  • Hello,
    I m using a text field with name “url”. This field is for front end posting. All works but i want restrict this field for only one domain “https://www.amazon.com”. So all the valide url need to begin with this domain.

    Can you help me?

    THX

  • Thanks for your reply.

    I put this in my function.php but it doesn’t work

    add_filter('acf/validate_value/key=field_5ab2ca68fcf2b', 'my_acf_validate_value', 10, 4);
    
    function my_acf_validate_value( $valid, $value, $field, $input ){
    
                    echo "erreur";
                    if( !$valid ) {
                                    return $valid;
    }
    
    $string = urldecode(get_field("url"));
    
    $parse = parse_url($string);
    echo $parse['host'];
    
    if ($parse['host'] != "www.amazon.fr") {
    
    		$valid = 'Erreur';
    
    	}
    
                    return $valid;
    
    }
  • You can’t echo anything in your filter. These filters are run using AJAX and the output you’re creating is probably causing an error in the what it returned by the AJAX request.

    If you want to see what’s going on in your script you can use the error log,

    like this

    
    error_log('$parse['host']);
    

    then you can look in the error log on your server to see it.

  • Ok so publish is ok but the condition doesn’t work…

    If i put http://www.amazon.fr url => unpublish
    If i put http://www.website.fr url => unpublish too

    erreur ajax display

    Normaly, this condition need to block other domain url.

    Do you know why ?

    By the way, log are empty.

  • If you’re trying to put something in the log and it is empty that is an indication that your filter is not running.

    But I’m not sure I know what you mean by => unpublish

    does that mean that you’re getting an error on all values?

  • Yes i have an error for all URL. Normaly error will apear only for URL without Amazon domain.

  • that problem is here in your code

    
    $string = urldecode(get_field("url"));
    

    try

    
    $string = urldecode($value);
    
Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Validation URL domain’ is closed to new replies.