• When using CF7 Version 5.1.7 a form submitted from a page where the user is not logged in fails with “There was an error trying to send your message. Please try again later.” and an orange border. This is because it fails the spam function in submissions.php line 293. The failure is for the call to verify_nonce() on line 312. It fails when not logged in because the hidden field containing the nonce is not generated.

    The generation is done in contact-form.php around line 460 by a call to wpcf7_create_nonce(). But this call is predicated on the user being logged in:

    
    		if ( $this->nonce_is_active() && is_user_logged_in() ) {
    			$hidden_fields['_wpnonce'] = wpcf7_create_nonce();
    

    I recommend changing this to make use of the subscriber_only setting in the form. With my change the current result can be obtained by setting subscriber_only:on. Without it the form will operate correctly even when not logged in.

    The suggested code is:

    
    // CJS nonce was not getting created if not logged in.  So submit was seen as spam and failed.
    // CJS By testing if subscriber_only is on and only then testing for being logged in
    // CJS we can determine when to create the nonce as follows:
    // CJS if subscriber_only is set to on you must be logged in the create the nonce
    // CJS but of it not set, or set to off, then being logged in is not required
    // CJS This allows forms to be used when not logged in, or more importantly not uses unless logged in
    // CJS by setting subscriber_only to on.
    //		if ( $this->nonce_is_active() && is_user_logged_in() ) {
    		if ( $this->nonce_is_active() && (!$this->is_true( 'subscribers_only' ) || is_user_logged_in()) ) {
    			$hidden_fields['_wpnonce'] = wpcf7_create_nonce();
    

    I have had to hack the code for this behavior so would like to know if it will be incorporated into a future release so that it survives plugin updates.
    Thanks for a great plugin!
    Colin

  • The topic ‘Form send fails when not logged in’ is closed to new replies.