Contact Form 7
Required fields radiobuttons and validation (3 posts)

  1. HansTis
    Posted 3 years ago #


    Great plugin, thanks! Sorry if this has been asked before, tried to search within the forum but could not find the answers so far.

    Is there a way to set radiobuttons as required? I use some here: http://www.oortgiese-camperverhuur.nl/site/reserveren/ and want to set them as required.

    And can I do a validation check like filling in only numerical characters in a telephone field?

    Regards, Hans.


  2. biastechnology
    Posted 3 years ago #

    Hi Hans,

    I've implemented this telephone validation code today and it's working great for me.

    Validate Telephone and FAX Numbers in Contact Form 7 This is for 11 digit numbers

    function is_number( $result, $tag ) {
    $type = $tag['type'];
    $name = $tag['name'];

    if ($name == 'phone' || $name == 'fax') { // Validation applies to these textfield names. Add more with || inbetween
    $stripped = preg_replace( '/\D/', '', $_POST[$name] );
    $_POST[$name] = $stripped;
    if( strlen( $_POST[$name] ) != 11 ) { // Number string must equal this
    $result['valid'] = false;
    $result['reason'][$name] = $_POST[$name] = 'Please enter an 11 digit phone number.';
    return $result;

    add_filter( 'wpcf7_validate_text', 'is_number', 11, 2 );
    add_filter( 'wpcf7_validate_text*', 'is_number', 11, 2 );

    Add it at the end of your themes/functions.php but before the '?>'

  3. HansTis
    Posted 3 years ago #

    Fastest support ever, thanks! I will past the code in the script tomorrow.

    Did you see my second question about the radiobuttons?

    Kind regards, Hans.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contact Form 7
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic