0

I'm working on a dynamic form where based on a visitor's selection of radio buttons certain <div> text and additional fields are shown or hidden. I would like to make some of these additional fields required but only if they are visible. Problem is: I can read php more than I can write it and jquery is a tad beyond my learning curve.

With the help of some Daniweb users I came up with the script below for the form here. When the form is submitted it returns a validation error and I'm not sure how to tweak the php code to check if parameter > 0 and if so then it should be validated. I'm using the Contact Form 7 wordpress plugin and Jquery Validation For Contact Form 7 but neither seems to deal directly with this type of validation.

$.fn.toggleFields = function(condition) {
    return this.each(function(i, el) {
        el = $(el);
        condition = (condition != null) ? condition : !el.is(':visible');
        el[condition ? 'show' : 'hide']().find(':input').attr('disabled', !condition);
    });
};
$(document).ready(function(){
    var dadAddr = $('#dad_address'),
        momAddr = $('#mom_address'),
        dadTrigger = $('#dadaddress'),
        momTrigger = $('#momaddress'),
        togetherTrigger = $('#bothparents');
    // hide and disable fields
    dadAddr.toggleFields(false);
    momAddr.toggleFields(false);
    togetherTrigger.click(function() {
        dadAddr.toggleFields(false);
        momAddr.toggleFields(false);
    });
    dadTrigger.click(function() {
        dadAddr.toggleFields(this.checked);
        momAddr.toggleFields(false);
    });
    momTrigger.click(function() {
        momAddr.toggleFields(this.checked);
        dadAddr.toggleFields(false);
    });

    $('#591').validate();
});

The php code for the Jquery Validation For Contact Form 7 plugin is below but I'm not sure which php code to post for the Contact Form 7 plugin since most of the files says (inactive) next to their name when I open them in the Wordpress plugin editor.

//add_action('admin_enqueue_scripts', 'jvcf7_validation_js');   


$jvcf7_show_label_error                         = get_option('jvcf7_show_label_error');
$jvcf7_highlight_error_field                    = get_option('jvcf7_highlight_error_field');    
$jvcf7_hide_contact_form_7_validation_error     = get_option('jvcf7_hide_contact_form_7_validation_error'); 

if (empty($jvcf7_show_label_error)){
    update_option('jvcf7_show_label_error', 'yes');
    $jvcf7_show_label_error                         = get_option('jvcf7_show_label_error');
}

if (empty($jvcf7_highlight_error_field)){
    update_option('jvcf7_highlight_error_field', 'yes');
    $jvcf7_highlight_error_field                    = get_option('jvcf7_highlight_error_field');    
}

if (empty($jvcf7_hide_contact_form_7_validation_error)){
    update_option('jvcf7_hide_contact_form_7_validation_error', 'yes');
    $jvcf7_hide_contact_form_7_validation_error     = get_option('jvcf7_hide_contact_form_7_validation_error'); 
}

$styleSheet = '.wpcf7-form span.wpcf7-not-valid-tip{ display:none !important;}';
if ($jvcf7_show_label_error == 'yes'){
    $styleSheet.='.wpcf7-form label.error{color:#900; font-size:11px; float:none;}';
} else {
    $styleSheet.='.wpcf7-form label.error{display:none !important;}';
}

if ($jvcf7_highlight_error_field == 'yes'){
    $styleSheet.='.wpcf7-form input.error, .wpcf7-form select.error, .wpcf7-form textarea.error{border-bottom:2px solid #900;outline: none;}';
}

add_action('wp_enqueue_scripts', 'jvcf7_validation_js');
function jvcf7_validation_js(){
  global $styleSheet;
  echo '<script> jvcf7_loading_url= "'.plugins_url('contact-form-7/images/ajax-loader.gif').'"</script>';
  wp_dequeue_script( 'contact-form-7' );
  wp_enqueue_script('jquery-form');
  wp_enqueue_script('jvcf7_jquery_validate', plugins_url('jquery-validation-for-contact-form-7/js/jquery.validate.min.js'), array('jquery'), '', true);
  wp_enqueue_script('jvcf7_validation_custom', plugins_url('jquery-validation-for-contact-form-7/js/jquery.jvcf7_validation.js'), '', '', true);
  echo '<style>'.$styleSheet.'</style>';

}
include('plugin_interface.php');
?>

Thanks in advance. Sorry for the newbie question.

Edited by fcvolunteer: added php code

2
Contributors
10
Replies
14
Views
4 Years
Discussion Span
Last Post by fcvolunteer
Featured Replies
  • **@LastMitch** Turned out to have nothing to do with php after all (although the last php file I included was in fact the php file dealing with my form) I ended up needing to populate the hidden field when it wasn't chosen, using javascript, and to get the validation to … Read More

0

@fcvolunteer

PHP Server side validation help

The script that you provided is in JQuery? Where is the PHP code?

0

@LastMitch thanks for catching that, sorry about that. I've added it to my original post although I'm not sure I posted the code for all of the relevant php files. (I sort of explained above)

Thanks!

0

@fcvolunteer

Just post the php code that has the validation.

0

@LastMitch I wasn't sure which worpress plugin php file was providing the validation code but I believe it's the one above which I'm posting here in it's entirety. If it seems like that's not the correct php file please let me know and I'll try to figure out which is the correct one. Thanks so much for your patience!

<?php
/* 
Plugin Name: Jquery Validation For Contact Form 7
Plugin URI: http://dineshkarki.com.np/plugins/jquery-validation-for-contact-form-7
Description: This plugin integrates jquery validation in contact form 7
Author: Dinesh Karki
Version: 0.2
Author URI: http://www.dineshkarki.com.np
*/

/*  Copyright 2012  Dinesh Karki  (email : dnesskarki@gmail.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as 
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

//add_action('admin_enqueue_scripts', 'jvcf7_validation_js');   


$jvcf7_show_label_error                         = get_option('jvcf7_show_label_error');
$jvcf7_highlight_error_field                    = get_option('jvcf7_highlight_error_field');    
$jvcf7_hide_contact_form_7_validation_error     = get_option('jvcf7_hide_contact_form_7_validation_error'); 

if (empty($jvcf7_show_label_error)){
    update_option('jvcf7_show_label_error', 'yes');
    $jvcf7_show_label_error                         = get_option('jvcf7_show_label_error');
}

if (empty($jvcf7_highlight_error_field)){
    update_option('jvcf7_highlight_error_field', 'yes');
    $jvcf7_highlight_error_field                    = get_option('jvcf7_highlight_error_field');    
}

if (empty($jvcf7_hide_contact_form_7_validation_error)){
    update_option('jvcf7_hide_contact_form_7_validation_error', 'yes');
    $jvcf7_hide_contact_form_7_validation_error     = get_option('jvcf7_hide_contact_form_7_validation_error'); 
}

$styleSheet = '.wpcf7-form span.wpcf7-not-valid-tip{ display:none !important;}';
if ($jvcf7_show_label_error == 'yes'){
    $styleSheet.='.wpcf7-form label.error{color:#900; font-size:11px; float:none;}';
} else {
    $styleSheet.='.wpcf7-form label.error{display:none !important;}';
}

if ($jvcf7_highlight_error_field == 'yes'){
    $styleSheet.='.wpcf7-form input.error, .wpcf7-form select.error, .wpcf7-form textarea.error{border-bottom:2px solid #900;outline: none;}';
}

add_action('wp_enqueue_scripts', 'jvcf7_validation_js');
function jvcf7_validation_js(){
  global $styleSheet;
  echo '<script> jvcf7_loading_url= "'.plugins_url('contact-form-7/images/ajax-loader.gif').'"</script>';
  wp_dequeue_script( 'contact-form-7' );
  wp_enqueue_script('jquery-form');
  wp_enqueue_script('jvcf7_jquery_validate', plugins_url('jquery-validation-for-contact-form-7/js/jquery.validate.min.js'), array('jquery'), '', true);
  wp_enqueue_script('jvcf7_validation_custom', plugins_url('jquery-validation-for-contact-form-7/js/jquery.jvcf7_validation.js'), '', '', true);
  echo '<style>'.$styleSheet.'</style>';

}
include('plugin_interface.php');
?>
0

@LastMitch This is the only other php file in either plugin that deals with anything related to validation (that I can find) Thanks!

<?php

function wpcf7_plugin_path( $path = '' ) {
    return path_join( WPCF7_PLUGIN_DIR, trim( $path, '/' ) );
}

function wpcf7_plugin_url( $path = '' ) {
    $url = untrailingslashit( WPCF7_PLUGIN_URL );

    if ( ! empty( $path ) && is_string( $path ) && false === strpos( $path, '..' ) )
        $url .= '/' . ltrim( $path, '/' );

    return $url;
}

function wpcf7_deprecated_function( $function, $version, $replacement = null ) {
    do_action( 'wpcf7_deprecated_function_run', $function, $replacement, $version );

    if ( WP_DEBUG && apply_filters( 'wpcf7_deprecated_function_trigger_error', true ) ) {
        if ( ! is_null( $replacement ) )
            trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since Contact Form 7 version %2$s! Use %3$s instead.', 'wpcf7' ), $function, $version, $replacement ) );
        else
            trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since Contact Form 7 version %2$s with no alternative available.', 'wpcf7' ), $function, $version ) );
    }
}

function wpcf7_messages() {
    $messages = array(
        'mail_sent_ok' => array(
            'description' => __( "Sender's message was sent successfully", 'wpcf7' ),
            'default' => __( 'Your message was sent successfully. Thanks.', 'wpcf7' )
        ),

        'mail_sent_ng' => array(
            'description' => __( "Sender's message was failed to send", 'wpcf7' ),
            'default' => __( 'Failed to send your message. Please try later or contact the administrator by another method.', 'wpcf7' )
        ),

        'validation_error' => array(
            'description' => __( "Validation errors occurred", 'wpcf7' ),
            'default' => __( 'Validation errors occurred. Please confirm the fields and submit it again.', 'wpcf7' )
        ),

        'accept_terms' => array(
            'description' => __( "There are terms that the sender must accept", 'wpcf7' ),
            'default' => __( 'Please accept the terms to proceed.', 'wpcf7' )
        ),

        'invalid_email' => array(
            'description' => __( "Email address that the sender entered is invalid", 'wpcf7' ),
            'default' => __( 'Email address seems invalid.', 'wpcf7' )
        ),

        'invalid_required' => array(
            'description' => __( "There is a field that the sender must fill in", 'wpcf7' ),
            'default' => __( 'Please fill the required field.', 'wpcf7' )
        )
    );

    return apply_filters( 'wpcf7_messages', $messages );
}

function wpcf7_get_default_template( $prop = 'form' ) {
    if ( 'form' == $prop )
        $template = wpcf7_default_form_template();
    elseif ( 'mail' == $prop )
        $template = wpcf7_default_mail_template();
    elseif ( 'mail_2' == $prop )
        $template = wpcf7_default_mail_2_template();
    elseif ( 'messages' == $prop )
        $template = wpcf7_default_messages_template();
    else
        $template = null;

    return apply_filters( 'wpcf7_default_template', $template, $prop );
}

function wpcf7_default_form_template() {
    $template =
        '<p>' . __( 'Your Name', 'wpcf7' ) . ' ' . __( '(required)', 'wpcf7' ) . '<br />' . "\n"
        . '    [text* your-name] </p>' . "\n\n"
        . '<p>' . __( 'Your Email', 'wpcf7' ) . ' ' . __( '(required)', 'wpcf7' ) . '<br />' . "\n"
        . '    [email* your-email] </p>' . "\n\n"
        . '<p>' . __( 'Subject', 'wpcf7' ) . '<br />' . "\n"
        . '    [text your-subject] </p>' . "\n\n"
        . '<p>' . __( 'Your Message', 'wpcf7' ) . '<br />' . "\n"
        . '    [textarea your-message] </p>' . "\n\n"
        . '<p>[submit "' . __( 'Send', 'wpcf7' ) . '"]</p>';

    return $template;
}

function wpcf7_default_mail_template() {
    $subject = '[your-subject]';
    $sender = '[your-name] <[your-email]>';
    $body = sprintf( __( 'From: %s', 'wpcf7' ), '[your-name] <[your-email]>' ) . "\n"
        . sprintf( __( 'Subject: %s', 'wpcf7' ), '[your-subject]' ) . "\n\n"
        . __( 'Message Body:', 'wpcf7' ) . "\n" . '[your-message]' . "\n\n" . '--' . "\n"
        . sprintf( __( 'This mail is sent via contact form on %1$s %2$s', 'wpcf7' ),
            get_bloginfo( 'name' ), get_bloginfo( 'url' ) );
    $recipient = get_option( 'admin_email' );
    $additional_headers = '';
    $attachments = '';
    $use_html = 0;
    return compact( 'subject', 'sender', 'body', 'recipient', 'additional_headers', 'attachments', 'use_html' );
}

function wpcf7_default_mail_2_template() {
    $active = false;
    $subject = '[your-subject]';
    $sender = '[your-name] <[your-email]>';
    $body = __( 'Message body:', 'wpcf7' ) . "\n" . '[your-message]' . "\n\n" . '--' . "\n"
        . sprintf( __( 'This mail is sent via contact form on %1$s %2$s', 'wpcf7' ),
            get_bloginfo( 'name' ), get_bloginfo( 'url' ) );
    $recipient = '[your-email]';
    $additional_headers = '';
    $attachments = '';
    $use_html = 0;
    return compact( 'active', 'subject', 'sender', 'body', 'recipient', 'additional_headers', 'attachments', 'use_html' );
}

function wpcf7_default_messages_template() {
    $messages = array();

    foreach ( wpcf7_messages() as $key => $arr ) {
        $messages[$key] = $arr['default'];
    }

    return $messages;
}

function wpcf7_upload_dir( $type = false ) {
    global $switched;

    $siteurl = get_option( 'siteurl' );
    $upload_path = trim( get_option( 'upload_path' ) );

    $main_override = is_multisite() && defined( 'MULTISITE' ) && is_main_site();

    if ( empty( $upload_path ) ) {
        $dir = WP_CONTENT_DIR . '/uploads';
    } else {
        $dir = $upload_path;

        if ( 'wp-content/uploads' == $upload_path ) {
            $dir = WP_CONTENT_DIR . '/uploads';
        } elseif ( 0 !== strpos( $dir, ABSPATH ) ) {
            // $dir is absolute, $upload_path is (maybe) relative to ABSPATH
            $dir = path_join( ABSPATH, $dir );
        }
    }

    if ( ! $url = get_option( 'upload_url_path' ) ) {
        if ( empty( $upload_path )
        || ( 'wp-content/uploads' == $upload_path )
        || ( $upload_path == $dir ) )
            $url = WP_CONTENT_URL . '/uploads';
        else
            $url = trailingslashit( $siteurl ) . $upload_path;
    }

    if ( defined( 'UPLOADS' ) && ! $main_override
    && ( ! isset( $switched ) || $switched === false ) ) {
        $dir = ABSPATH . UPLOADS;
        $url = trailingslashit( $siteurl ) . UPLOADS;
    }

    if ( is_multisite() && ! $main_override
    && ( ! isset( $switched ) || $switched === false ) ) {

        if ( defined( 'BLOGUPLOADDIR' ) )
            $dir = untrailingslashit( BLOGUPLOADDIR );

        $url = str_replace( UPLOADS, 'files', $url );
    }

    $uploads = apply_filters( 'wpcf7_upload_dir', array( 'dir' => $dir, 'url' => $url ) );

    if ( 'dir' == $type )
        return $uploads['dir'];
    if ( 'url' == $type )
        return $uploads['url'];

    return $uploads;
}

function wpcf7_l10n() {
    $l10n = array(
        'af' => __( 'Afrikaans', 'wpcf7' ),
        'sq' => __( 'Albanian', 'wpcf7' ),
        'ar' => __( 'Arabic', 'wpcf7' ),
        'hy_AM' => __( 'Armenian', 'wpcf7' ),
        'az_AZ' => __( 'Azerbaijani', 'wpcf7' ),
        'bn_BD' => __( 'Bangla', 'wpcf7' ),
        'eu' => __( 'Basque', 'wpcf7' ),
        'be_BY' => __( 'Belarusian', 'wpcf7' ),
        'bs' => __( 'Bosnian', 'wpcf7' ),
        'pt_BR' => __( 'Brazilian Portuguese', 'wpcf7' ),
        'bg_BG' => __( 'Bulgarian', 'wpcf7' ),
        'ca' => __( 'Catalan', 'wpcf7' ),
        'zh_CN' => __( 'Chinese (Simplified)', 'wpcf7' ),
        'zh_TW' => __( 'Chinese (Traditional)', 'wpcf7' ),
        'hr' => __( 'Croatian', 'wpcf7' ),
        'cs_CZ' => __( 'Czech', 'wpcf7' ),
        'da_DK' => __( 'Danish', 'wpcf7' ),
        'nl_NL' => __( 'Dutch', 'wpcf7' ),
        'en_US' => __( 'English', 'wpcf7' ),
        'eo_EO' => __( 'Esperanto', 'wpcf7' ),
        'et' => __( 'Estonian', 'wpcf7' ),
        'fi' => __( 'Finnish', 'wpcf7' ),
        'fr_FR' => __( 'French', 'wpcf7' ),
        'gl_ES' => __( 'Galician', 'wpcf7' ),
        'ka_GE' => __( 'Georgian', 'wpcf7' ),
        'de_DE' => __( 'German', 'wpcf7' ),
        'el' => __( 'Greek', 'wpcf7' ),
        'he_IL' => __( 'Hebrew', 'wpcf7' ),
        'hi_IN' => __( 'Hindi', 'wpcf7' ),
        'hu_HU' => __( 'Hungarian', 'wpcf7' ),
        'id_ID' => __( 'Indonesian', 'wpcf7' ),
        'it_IT' => __( 'Italian', 'wpcf7' ),
        'ja' => __( 'Japanese', 'wpcf7' ),
        'ko_KR' => __( 'Korean', 'wpcf7' ),
        'lv' => __( 'Latvian', 'wpcf7' ),
        'lt_LT' => __( 'Lithuanian', 'wpcf7' ),
        'mk_MK' => __( 'Macedonian', 'wpcf7' ),
        'ms_MY' => __( 'Malay', 'wpcf7' ),
        'ml_IN' => __( 'Malayalam', 'wpcf7' ),
        'mt_MT' => __( 'Maltese', 'wpcf7' ),
        'nb_NO' => __( 'Norwegian', 'wpcf7' ),
        'fa_IR' => __( 'Persian', 'wpcf7' ),
        'pl_PL' => __( 'Polish', 'wpcf7' ),
        'pt_PT' => __( 'Portuguese', 'wpcf7' ),
        'ru_RU' => __( 'Russian', 'wpcf7' ),
        'ro_RO' => __( 'Romanian', 'wpcf7' ),
        'sr_RS' => __( 'Serbian', 'wpcf7' ),
        'si_LK' => __( 'Sinhala', 'wpcf7' ),
        'sk_SK' => __( 'Slovak', 'wpcf7' ),
        'sl_SI' => __( 'Slovene', 'wpcf7' ),
        'es_ES' => __( 'Spanish', 'wpcf7' ),
        'sv_SE' => __( 'Swedish', 'wpcf7' ),
        'ta' => __( 'Tamil', 'wpcf7' ),
        'th' => __( 'Thai', 'wpcf7' ),
        'tl' => __( 'Tagalog', 'wpcf7' ),
        'tr_TR' => __( 'Turkish', 'wpcf7' ),
        'uk' => __( 'Ukrainian', 'wpcf7' ),
        'vi' => __( 'Vietnamese', 'wpcf7' )
    );

    return $l10n;
}

function wpcf7_is_rtl() {
    if ( function_exists( 'is_rtl' ) )
        return is_rtl();

    return false;
}

function wpcf7_ajax_loader() {
    $url = wpcf7_plugin_url( 'images/ajax-loader.gif' );

    return apply_filters( 'wpcf7_ajax_loader', $url );
}

function wpcf7_verify_nonce( $nonce, $action = -1 ) {
    if ( substr( wp_hash( $action, 'nonce' ), -12, 10 ) == $nonce )
        return true;

    return false;
}

function wpcf7_create_nonce( $action = -1 ) {
    return substr( wp_hash( $action, 'nonce' ), -12, 10 );
}

function wpcf7_blacklist_check( $target ) {
    $mod_keys = trim( get_option( 'blacklist_keys' ) );

    if ( empty( $mod_keys ) )
        return false;

    $words = explode( "\n", $mod_keys );

    foreach ( (array) $words as $word ) {
        $word = trim( $word );

        if ( empty( $word ) )
            continue;

        if ( preg_match( '#' . preg_quote( $word, '#' ) . '#', $target ) )
            return true;
    }

    return false;
}

function wpcf7_array_flatten( $input ) {
    if ( ! is_array( $input ) )
        return array( $input );

    $output = array();

    foreach ( $input as $value )
        $output = array_merge( $output, wpcf7_array_flatten( $value ) );

    return $output;
}

?>
0

@fcvolunteer

No, it's not those files. The file looks something like this:

http://anvweb.com/blog/server-side-form-validation-with-jquery-plugin-and-php/

Your php code should look the same or little similar to code on the website!

You have an optional to used the code from link to modify it to your code or you can look for that file and fixed that bug. My advice used the code from link. Save you a lot time and energy.

0

@LastMitch I know I'm making you crazy and I'm really embarrassed but I totally don't feel equipped to modify the code from your link. I'm positive I'll mess it up. I think I may have found the correct php file below

<?php
/**
** A base module for [text], [text*], [email], and [email*]
**/

/* Shortcode handler */

wpcf7_add_shortcode( 'text', 'wpcf7_text_shortcode_handler', true );
wpcf7_add_shortcode( 'text*', 'wpcf7_text_shortcode_handler', true );
wpcf7_add_shortcode( 'email', 'wpcf7_text_shortcode_handler', true );
wpcf7_add_shortcode( 'email*', 'wpcf7_text_shortcode_handler', true );

function wpcf7_text_shortcode_handler( $tag ) {
    if ( ! is_array( $tag ) )
        return '';

    $type = $tag['type'];
    $name = $tag['name'];
    $options = (array) $tag['options'];
    $values = (array) $tag['values'];

    if ( empty( $name ) )
        return '';

    $validation_error = wpcf7_get_validation_error( $name );

    $atts = $id_att = $size_att = $maxlength_att = '';
    $tabindex_att = $title_att = '';

    $class_att = wpcf7_form_controls_class( $type, 'wpcf7-text' );

    if ( 'email' == $type || 'email*' == $type )
        $class_att .= ' wpcf7-validates-as-email';

    if ( $validation_error )
        $class_att .= ' wpcf7-not-valid';

    foreach ( $options as $option ) {
        if ( preg_match( '%^id:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
            $id_att = $matches[1];

        } elseif ( preg_match( '%^class:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
            $class_att .= ' ' . $matches[1];

        } elseif ( preg_match( '%^([0-9]*)[/x]([0-9]*)$%', $option, $matches ) ) {
            $size_att = (int) $matches[1];
            $maxlength_att = (int) $matches[2];

        } elseif ( preg_match( '%^tabindex:(\d+)$%', $option, $matches ) ) {
            $tabindex_att = (int) $matches[1];

        }
    }

    $value = (string) reset( $values );

    if ( wpcf7_script_is() && preg_grep( '%^watermark$%', $options ) ) {
        $class_att .= ' wpcf7-use-title-as-watermark';
        $title_att .= sprintf( ' %s', $value );
        $value = '';

    } elseif ( empty( $value ) && is_user_logged_in() ) {
        $user = wp_get_current_user();

        $user_options = array(
            'default:user_login' => 'user_login',
            'default:user_email' => 'user_email',
            'default:user_url' => 'user_url',
            'default:user_first_name' => 'first_name',
            'default:user_last_name' => 'last_name',
            'default:user_nickname' => 'nickname',
            'default:user_display_name' => 'display_name' );

        foreach ( $user_options as $option => $prop ) {
            if ( preg_grep( '%^' . $option . '$%', $options ) ) {
                $value = $user->{$prop};
                break;
            }
        }
    }

    if ( wpcf7_is_posted() && isset( $_POST[$name] ) )
        $value = stripslashes_deep( $_POST[$name] );

    if ( $id_att )
        $atts .= ' id="' . trim( $id_att ) . '"';

    if ( $class_att )
        $atts .= ' class="' . trim( $class_att ) . '"';

    if ( $size_att )
        $atts .= ' size="' . $size_att . '"';
    else
        $atts .= ' size="40"'; // default size

    if ( $maxlength_att )
        $atts .= ' maxlength="' . $maxlength_att . '"';

    if ( '' !== $tabindex_att )
        $atts .= sprintf( ' tabindex="%d"', $tabindex_att );

    if ( $title_att )
        $atts .= sprintf( ' title="%s"', trim( esc_attr( $title_att ) ) );

    $html = '<input type="text" name="' . $name . '" value="' . esc_attr( $value ) . '"' . $atts . ' />';

    $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . $html . $validation_error . '</span>';

    return $html;
}


/* Validation filter */

add_filter( 'wpcf7_validate_text', 'wpcf7_text_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_text*', 'wpcf7_text_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_email', 'wpcf7_text_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_email*', 'wpcf7_text_validation_filter', 10, 2 );

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

    $_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );

    if ( 'text*' == $type ) {
        if ( '' == $_POST[$name] ) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message( 'invalid_required' );
        }
    }

    if ( 'email' == $type || 'email*' == $type ) {
        if ( 'email*' == $type && '' == $_POST[$name] ) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message( 'invalid_required' );
        } elseif ( '' != $_POST[$name] && ! is_email( $_POST[$name] ) ) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message( 'invalid_email' );
        }
    }

    return $result;
}


/* Tag generator */

add_action( 'admin_init', 'wpcf7_add_tag_generator_text_and_email', 15 );

function wpcf7_add_tag_generator_text_and_email() {
    if ( ! function_exists( 'wpcf7_add_tag_generator' ) )
        return;

    wpcf7_add_tag_generator( 'text', __( 'Text field', 'wpcf7' ),
        'wpcf7-tg-pane-text', 'wpcf7_tg_pane_text' );

    wpcf7_add_tag_generator( 'email', __( 'Email field', 'wpcf7' ),
        'wpcf7-tg-pane-email', 'wpcf7_tg_pane_email' );
}

function wpcf7_tg_pane_text( &$contact_form ) {
    wpcf7_tg_pane_text_and_email( 'text' );
}

function wpcf7_tg_pane_email( &$contact_form ) {
    wpcf7_tg_pane_text_and_email( 'email' );
}

function wpcf7_tg_pane_text_and_email( $type = 'text' ) {
    if ( 'email' != $type )
        $type = 'text';

?>
<div id="wpcf7-tg-pane-<?php echo $type; ?>" class="hidden">
<form action="">
<table>
<tr><td><input type="checkbox" name="required" />&nbsp;<?php echo esc_html( __( 'Required field?', 'wpcf7' ) ); ?></td></tr>
<tr><td><?php echo esc_html( __( 'Name', 'wpcf7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>
</table>

<table>
<tr>
<td><code>id</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
<input type="text" name="id" class="idvalue oneline option" /></td>

<td><code>class</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
<input type="text" name="class" class="classvalue oneline option" /></td>
</tr>

<tr>
<td><code>size</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
<input type="text" name="size" class="numeric oneline option" /></td>

<td><code>maxlength</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
<input type="text" name="maxlength" class="numeric oneline option" /></td>
</tr>

<tr>
<td colspan="2"><?php echo esc_html( __( 'Akismet', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
<?php if ( 'text' == $type ) : ?>
<input type="checkbox" name="akismet:author" class="exclusive option" />&nbsp;<?php echo esc_html( __( "This field requires author's name", 'wpcf7' ) ); ?><br />
<input type="checkbox" name="akismet:author_url" class="exclusive option" />&nbsp;<?php echo esc_html( __( "This field requires author's URL", 'wpcf7' ) ); ?>
<?php else : ?>
<input type="checkbox" name="akismet:author_email" class="option" />&nbsp;<?php echo esc_html( __( "This field requires author's email address", 'wpcf7' ) ); ?>
<?php endif; ?>
</td>
</tr>

<tr>
<td><?php echo esc_html( __( 'Default value', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /><input type="text" name="values" class="oneline" /></td>

<td>
<br /><input type="checkbox" name="watermark" class="option" />&nbsp;<?php echo esc_html( __( 'Use this text as watermark?', 'wpcf7' ) ); ?>
</td>
</tr>
</table>

<div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?><br /><input type="text" name="<?php echo $type; ?>" class="tag" readonly="readonly" onfocus="this.select()" /></div>

<div class="tg-mail-tag"><?php echo esc_html( __( "And, put this code into the Mail fields below.", 'wpcf7' ) ); ?><br /><span class="arrow">&#11015;</span>&nbsp;<input type="text" class="mail-tag" readonly="readonly" onfocus="this.select()" /></div>
</form>
</div>
<?php
}

?>

If this is the one, what would I add to check that the value of a certain field is greater than "0" and if so tell it to continue with validation?

Thanks

0

@fcvolunteer

If this is the one, what would I add to check that the value of a certain field is greater than "0" and if so tell it to continue with validation?

So far base on your selection of code. You don't really know which files or the code you are looking for? That is not good. It's seems to me you are guessing which files. I want you to know that I'm not gonna read all the code!

My question you are using Wordpress plugin and a JQuery plugin together?

Usually any plugin you don't mess around with!

If the plugin doesn't work correctly it usually means it's not comparable with your code! For example:

function wpcf7_deprecated_function( $function, $version, $replacement = null ) {
    do_action( 'wpcf7_deprecated_function_run', $function, $replacement, $version );

Read this:

http://codex.wordpress.org/Category:Deprecated_Functions

Hopefully this info will let you know more about your code.

I don't think anyone from DaniWeb member in the PHP section can help you with this.

I can't help you anymore either the link or you are on your own!

1

@LastMitch

Turned out to have nothing to do with php after all (although the last php file I included was in fact the php file dealing with my form) I ended up needing to populate the hidden field when it wasn't chosen, using javascript, and to get the validation to skip the hidden fields.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.