Skip to content

Instantly share code, notes, and snippets.

@alt-karate
Created November 13, 2020 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alt-karate/87db9b71d67f5c7cae965915926894cc to your computer and use it in GitHub Desktop.
Save alt-karate/87db9b71d67f5c7cae965915926894cc to your computer and use it in GitHub Desktop.
//メールフォームの textarea に日本語が無ければ送信できない(contact form7)
add_filter('wpcf7_validate_textarea', 'wpcf7_validation_textarea_hiragana', 10, 2);
add_filter('wpcf7_validate_textarea*', 'wpcf7_validation_textarea_hiragana', 10, 2);
function wpcf7_validation_textarea_hiragana($result, $tag)
{
$name = $tag['name'];
$value = (isset($_POST[$name])) ? (string) $_POST[$name] : '';
if ($value !== '' && !preg_match('/[ぁ-ん]/u', $value)) {
$result['valid'] = false;
$result['reason'] = array($name => '日本語で入力してください。');
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment