1.
Register two shortcode:
wpcf7_add_shortcode( 'num', 'wpcf7_text_shortcode_handler', true );
wpcf7_add_shortcode( 'num*', 'wpcf7_text_shortcode_handler', true );
2.
Register the validation filter and implement the filter:
add_filter( 'wpcf7_validate_num', 'wpcf7_num_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_num*', 'wpcf7_num_validation_filter', 10, 2 );
function wpcf7_num_validation_filter( $result, $tag ) {
$type = $tag['type'];
$name = $tag['name'];
$_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );
if ( 'num' == $type || 'num*' == $type ) {
if ( 'num*' == $type && '' == $_POST[$name] ) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message( 'invalid_required' );
} elseif ( '' != $_POST[$name] && ! is_numeric( $_POST[$name] ) ) {
$result['valid'] = false;
$result['reason'][$name] = 'Numbers are required.';
}
}
return $result;
}
3.
You can try to add your Tag Generator for the new type, but I just don't bother. To use the new field, it is the same as using [text] field, e.g. [num mobile /10 class:mobile]
Nice solution, however I am receiving an error on submission. It reads:
ReplyDeleteFailed to send your message. Please try later or contact the administrator by another method.
Any ideas on a fix?
TIA
~Rat
sorry for digging out such an old post but I just wanted to confirm that this hack works
ReplyDeletewe've just introduced it into client's website
Contact form 7 Version 3.2.1
Wordpress version 3.4.1
Hello! I just wish to give an enormous thumbs up for the nice info you've got right here on this post. I will probably be coming back to your weblog for more soon! wordpress autoblog setup
ReplyDelete