Home › Forums › Backend Issues (wp-admin) › 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
You need to use this hook/filter https://www.advancedcustomfields.com/resources/acf-validate_value/
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);
The topic ‘Validation URL domain’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.