How to continue executing after JavaScript validation

I’m running a JavaScript validation during wp_handle_upload_prefilter

$file will only return if the JavaScript validation return true.

add_filter(‘wp_handle_upload_prefilter’, ‘custom_upload_filter’ );
function custom_upload_filter( $file ){
$data = json_encode($file);
$name = json_encode($file[‘name’]);

echo “<script type=’text/javascript’>
validation($data); // will return Boolean. Only if true should continue return $file
</script>”;

return $file;
}

I’ve tried to write into cookies and have PHP read the cookie later as such :

if (validation($data)) {
document.cookie = ‘myCookie_’ + $name + ‘= true’;
} else {
document.cookie = ‘myCookie_’ + $name + ‘= data’;
}

but it doesn’t work

Read more here:: How to continue executing after JavaScript validation

Leave a Reply

Your email address will not be published. Required fields are marked *