WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. HansTis
    Member
    Posted 1 year ago #

    Hi,

    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.

    http://wordpress.org/extend/plugins/contact-form-7/

  2. biastechnology
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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

About this Topic