Forum Replies Created

Viewing 15 replies - 16 through 30 (of 33 total)
  • Thread Starter StevenP94

    (@stevenp94)

    Hi, it works because I used a required field to un-hide the group so to complete required data you automatically unhide the group and all works as expected.

    removing the required flag from the email field, you will notice that the email is sent without checking the checkbox and no error message is given, try this new form:

    https://conditional-fields-cf7.bdwm.be/form-tester/?hash=0f21bdf71bd1109f782f2c1a9beb7463

    if you put data in the Il tuo Nome and Oggetto you will notice that the checkbox is not taken in account

    • This reply was modified 2 years, 10 months ago by StevenP94.
    Thread Starter StevenP94

    (@stevenp94)

    removing the attributes, still not working – so weird!

    Thread Starter StevenP94

    (@stevenp94)

    Yes, Jules, I see, but my original test form still not working:

    https://conditional-fields-cf7.bdwm.be/form-tester/?hash=d3d4a571de454dcae614fc3e56100ec7

    maybe are the clear_on_hide or the inline attributes, I’m making some test on that

    Thread Starter StevenP94

    (@stevenp94)

    Done, just waiting for moderation.

    Thread Starter StevenP94

    (@stevenp94)

    <?php
    /**
    * Plugin Name: My Plugin
    * Plugin URI: https://www.yourwebsiteurl.com/
    * Description: This is the very first plugin I ever created.
    * Version: 1.0
    * Author: Steven
    * Author URI: https://yourwebsiteurl.com/
    **/
    
    // this code is an extract of wpgdprc plugin to make tests on CF7 validation
    
    add_action( 'wpcf7_init', 'addFormTagSupport' );
    add_filter( 'wpcf7_validate_wpgdprc', 'validateField', 10, 2 );
    
    	function addFormTagSupport() {
    		if ( ! function_exists( 'wpcf7_add_form_tag' ) ) {
    			return;
    		}
    		wpcf7_add_form_tag( getFieldTag(), 'addFormTagHandler' );
    	}
    
    	/**
    	 * @param mixed $tag (array|WPCF7_FormTag)
    	 *
    	 * @return string
    	 */
    	function addFormTagHandler( $tag = [] ): string {
    		$tag = validateFormTag( $tag );
    		if ( empty( $tag ) ) {
    			return '';
    		}
    
    		$tag->name   = getFieldTag();
    		$first_label = reset( $tag->labels );
    		$label       = ! empty( $first_label ) ? esc_html( $first_label ) : getCheckboxTextByForm();
    
    		$class     = [ wpcf7_form_controls_class( $tag->type, 'wpcf7-validates-as-required' ) ];
    		$has_error = wpcf7_get_validation_error( $tag->name );
    		if ( $has_error ) {
    			$class[] = 'wpcf7-not-valid';
    		}
    
    		$field_atts = [
    			'type'          => 'checkbox',
    			'name'          => $tag->name,
    			'value'         => 1,
    			'tabindex'      => $tag->get_option( 'tabindex', 'signed_int', true ),
    			'aria-required' => 'true',
    			'aria-invalid'  => $has_error ? 'true' : 'false',
    		];
    
    		$field = [ '<input %2$s />', '<span class="wpcf7-list-item-label">%1$s</span>' ];
    		if ( $tag->has_option( 'label_first' ) ) {
    			$field = array_reverse( $field );
    		}
    		$output = sprintf( implode( '', $field ), esc_html( $label ), wpcf7_format_atts( $field_atts ) );
    
    		if ( $tag->has_option( 'use_label_element' ) ) {
    			$output = '<label>' . $output . '</label>';
    		}
    
    		$wrapper_atts = [
    			'class' => $tag->get_class_option( implode( ' ', $class ) ),
    			'id'    => $tag->get_id_option(),
    		];
    
    		return sprintf(
    			'<span class="wpcf7-form-control-wrap %1s"><span %2s>%3s</span>%4s</span>',
    			sanitize_html_class( $tag->name ),
    			wpcf7_format_atts( $wrapper_atts ),
    			'<span class="wpcf7-list-item">' . $output . '</span>',
    			$has_error
    		);
    	}
    
    	/**
    	 * Allows for wrapping the field tag (like in the CF form & email)
    	 *
    	 * @param bool $wrapped
    	 *
    	 * @return string
    	 */
    	function getFieldTag( bool $wrapped = false ): string {
    		$tag = 'wpgdprc';
    
    		return $wrapped ? '[' . $tag . ']' : $tag;
    	}
    
    	/**
    	 * Gets checkbox text for specific form
    	 *
    	 * @param int|string $form_id
    	 *
    	 * @return string
    	 */
    	function getCheckboxTextByForm( $form_id = 0 ): string {
    		return 'testo aggiunto al check';
    	}
    
    	/**
    	 * Validates form tag (and checks if it is the WPGDRPC form tag)
    	 *
    	 * @param mixed $tag (array|WPCF7_FormTag)
    	 *
    	 * @return mixed (false|WPCF7_FormTag)
    	 */
    	function validateFormTag( $tag = [] ) {
    		if ( ! class_exists( 'WPCF7_FormTag' ) ) {
    			return false;
    		}
    
    		$tag = is_array( $tag ) ? new \WPCF7_FormTag( $tag ) : $tag;
    		if ( $tag->type !== getFieldTag() ) {
    			return false;
    		}
    
    		return $tag;
    	}
    
    	/**
    	 * @param mixed $result
    	 * @param mixed $tag (array|WPCF7_FormTag)
    	 *
    	 * @return mixed (WPCF7_Validation)
    	 */
    	function validateField( $result, $tag = [] ) {
    		if ( ! class_exists( 'WPCF7_Validation' ) ) {
    			return $result;
    		}
    		if ( ! $result instanceof \WPCF7_Validation ) {
    			return $result;
    		}
    
    		$tag = validateFormTag( $tag );
    		if ( empty( $tag ) ) {
    			return $result;
    		}
    
    		$value = false;
    		if ( ! empty( $_POST[ getFieldTag() ] ) ) {
    			$value = filter_var( wp_unslash( $_POST[ getFieldTag() ] ), FILTER_VALIDATE_BOOLEAN );
    		}
    		if ( ! empty( $value ) ) {
    			return $result;
    		}
    
    		$key     = '_wpcf7';
    		$form_id = ! empty( $_POST[ $key ] ) && is_numeric( $_POST[ $key ] ) ? (int) $_POST[ $key ] : 0;
    		if ( empty( $form_id ) ) {
    			return $result;
    		}
    
    		$tag->name = getFieldTag();
    		$result->invalidate( $tag,  'You must fill the checkbox!' );
    
    		return $result;
    	}
    Thread Starter StevenP94

    (@stevenp94)

    The problem is not the mail, that part works.
    The problem is that the validation on thecheckbox is bypassed by hidden groups.

    I can give you a simple plugin code that I wrote to make tests, maybe you can help me to see where is wrong and why is bypassed by hidden groups.

    Just let me know if is possible and how to give you the code. Hop that this don’t break any rules.

    Regards.

    Thread Starter StevenP94

    (@stevenp94)

    This is a test form:

    https://conditional-fields-cf7.bdwm.be/form-tester/?hash=732ed3af6d6cc913570a5d0279fd0672

    Nothing special, just a test form made using the standard contact form example module.

    the [wpgdprc] tag is the shortcode added by

    Cookie Information | Free GDPR Consent Solution

    this plugins adds the tag in the form and at runtime is replaced by a required checkbox.

    If all is shown, all works fine and the validation of required checkbox works.
    If I hide a group (just the default condition in my example) the checkbox is not required anymore.

    Hope that this can help.

    P.S. I have the same problem if I make custom code to do that using:

    wpcf7_add_form_tag( 'wpgdprc', 'addFormTagHandler' );
    add_filter( 'wpcf7_validate_wpgdprc','myvalidation',10,2)

    the invalidate is executed but has no effect
    $result->invalidate( $tag, 'this is required field' );

    • This reply was modified 2 years, 10 months ago by StevenP94.
    • This reply was modified 2 years, 10 months ago by StevenP94.
    Thread Starter StevenP94

    (@stevenp94)

    @jdembowski thanks for your advice, I missed that. Sorry for offering that.

    Thread Starter StevenP94

    (@stevenp94)

    Thanks for your kind reply.

    I’m sorry but I can’t remove that plugin:
    I have more than 100 contact forms and the wp gdpr compliance plugin manage other aspects of privacy and cookies in addition to the acceptance check.

    The shortcut that add this control is just before the submit and is not inside a group, and it works like the acceptance field. The problem is that it uses custom validation that doesn’t work when there is an hidden group (anywhere in the form)

    I made a test site for this, and I can give you access if you need.

    I apologize for my english

    • This reply was modified 2 years, 10 months ago by StevenP94.
    Thread Starter StevenP94

    (@stevenp94)

    I found a cause:
    I’m using Conditional Fields for Contact Form 7 and when there are hidden fields, this instruction

    $result->invalidate( $tag, self::getErrorTextByForm( $form_id ) );

    has no effect.

    This is into the ContactForm.php at line 470

    I’m writing on support page of that plugin for this.

    During my tests I found another error:
    in the same file Integration/Plugins/ContactForm.php, in the

    public function addAcceptedDate( int $form_id = 0 ) {

    there is a missing ! in the line 323, in this way the _mail meta is never populated with the [wpgdprc] tag.

    I changed from:

    $pattern = '/(\[' . $this->getFieldTag() . '\])/';
                    preg_match( $pattern, $value['body'], $matches );
                    if ( empty( $matches ) ) {
                            return;
                    }

    to

    $pattern = '/(\[' . $this->getFieldTag() . '\])/';
                    preg_match( $pattern, $value['body'], $matches );
                    if ( ! empty( $matches ) ) {
                            return;
                    }

    Still investigating

    I’m sorry but I think that this problem is still there
    After upgrading to version 2.0.2 if I try to send a form without checking the GDPR no messages is shown.
    In addiction on the mail I receive the GDPR message 2 times.

    Thread Starter StevenP94

    (@stevenp94)

    The same with 4.9.1.1 – Any news on a workaround / solution ?
    Do yuo need a sample site ?

    Thread Starter StevenP94

    (@stevenp94)

    Thanks for your reply. Yes the calendar is activated. I’m currently using 4.9.0, this is the last version working. I’m on a linux ubuntu 18.04.2 box with PHP 7.2.
    Any update of my current version break the site with the errors that I posted on my first message.
    Of course I was lucky and had a backup to recover working version.
    I have event ticket version 4.10.3 and event ticket plus version 4.10.2 on that site. I’m waiting for the events calendar working before try to update them.

    Thanks again for your support and excuse me for my english.

    I have a little ‘upcoming events’ on the home page of my theme (a child theme).

    From the 4.9.0.2 version, I started to have this in my error log:

    PHP Fatal error:  Uncaught Error: Call to undefined function tribe_get_events() in /var/www/xxxxxx/wp-content/themes/DeepFocus-child/home.php:31
    Stack trace:
    #0 /var/www/xxxxxx/wp-includes/template-loader.php(77): include()
    #1 /var/www/xxxxxx/wp-blog-header.php(19): require_once('/var/www/xxxxxx...')
    #2 /var/www/xxxxxx/index.php(17): require('/var/www/xxxxxx...')
    #3 {main}
      thrown in /var/www/xxxxxx/wp-content/themes/DeepFocus-child/home.php on line 31, referer: https://www.xxxxxx.xx//wp-admin/plugins.php
    
    PHP Fatal error:  Uncaught Error: Call to undefined function tribe_is_event_query() in /var/www/xxxxxx/wp-content/themes/DeepFocus-child/includes/breadcrumbs.php:18
    Stack trace:
    #0 /var/www/xxxxxx/wp-includes/template.php(706): require()
    #1 /var/www/xxxxxx/wp-includes/template.php(653): load_template('/var/www/xxxxxx...', false)
    #2 /var/www/xxxxxx/wp-includes/general-template.php(157): locate_template(Array, true, false)
    #3 /var/www/xxxxxx/wp-content/themes/DeepFocus/404.php(10): get_template_part('includes/breadc...')
    #4 /var/www/xxxxxx/wp-includes/template-loader.php(77): include('/var/www/xxxxxx...')
    #5 /var/www/xxxxxx/wp-blog-header.php(19): require_once('/var/www/xxxxxx...')
    #6 /var/www/xxxxxx/index.php(17): require('/var/www/xxxxxx...')
    #7 {main}
      thrown in /var/www/xxxxxx/wp-content/themes/DeepFocus-child/includes/breadcrumbs.php on line 18, referer: https://www.xxxxxx.xx/
    

    Thanks a lot it worked for me, too.

Viewing 15 replies - 16 through 30 (of 33 total)