Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Created June 26, 2019 09:14
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 Pebblo/be5b93e1912f89e8f2c1e7c66c33fcf3 to your computer and use it in GitHub Desktop.
Save Pebblo/be5b93e1912f89e8f2c1e7c66c33fcf3 to your computer and use it in GitHub Desktop.
Example of how to override the validation stratey used on a EE_Phone_Input field.
<?php //Please do not include the opening PHP tag
add_filter('FHEE__EE_Form_Input_Base___construct__input_args', 'tw_ee_EE_Form_Input_Base___construct__input_args', 10, 2);
function tw_ee_EE_Form_Input_Base___construct__input_args( $input_args, $input ) {
if( $input instanceof EE_Phone_Input ) {
if( $input->has_validation_strategy('EE_Text_Validation_Strategy') ) {
$input->remove_validation_strategy('EE_Text_Validation_Strategy');
$input->add_validation_strategy(
new EE_Text_Validation_Strategy(
__('Please enter a valid phone number. Eg 123-456-7890 or 1234567890', 'event_espresso'),
'~^(([\d]{15})|(^[\d]{3}-[\d]{3}-[\d]{4}))$~'
)
);
}
}
return $input_args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment