• Hi,

    I’ve discovered an error while using the shortcode [email-download download_id="X" contact_form_id="Y"]. The class Email_Before_Download_Process assumes that the email and name fields are named your-email and your-name, which isn’t always the case. The log function throws an error:

    Notice: Undefined index: your-name in /wp-content/plugins/email-before-download/includes/class-email-before-download-process.php on line 243

    The send_email, generate_links and check_blacklist functions in the same file also assume the use of a field named your-email.

    • This topic was modified 6 years, 10 months ago by absolutist.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author mandsconsulting

    (@mandsconsulting)

    Hi @absolutist,

    Yes, we have always required your-name and your-email specifically in cf7. We will review the readme to make sure that is clear. Or are you saying it used to work without them at some version of EBD and now it doesn’t?

    (Btw, the formatting of your post is hard to read and some words are hidden, but hope I got the gist).

    Thread Starter absolutist

    (@absolutist)

    Thanks for the quick reply ??

    I’m using a “first name” and “last name” field in my form. Contact Form 7 has hooks, but are those fired before EBD does it’s work? If so, I could always add a “fake your-name field” in a hook by combining the first and last name fields.

    (Don’t know about my post formatting, I’ve used the default backticks for code… Seems you got my point though)

    Plugin Author mandsconsulting

    (@mandsconsulting)

    Hi @absolutist

    Got it. Added to our internal enhancements backlog for review and possible inclusion in upcoming release.

    Thread Starter absolutist

    (@absolutist)

    Allright, I did some more testing. The hooks solution doesn’t work, because the plugin takes the $_POST data directly. The problem lies in the Email_Before_Download_Process class.

    This part specifically:

    
    public function process_cf7($form_obj)
    {
        if (!isset($_POST['ebd_settings'])) {
            return $form_obj;  // make sure this only fires when there is EBD info
        }
        $post_data = $_POST;
        $user_input = [];
        $settings = $this->parse_post_array($post_data['ebd_settings']);
        $downloads = $this->parse_post_array($post_data['ebd_downloads']);
        foreach ($post_data as $key => $value) {
            if (!is_array($value))
                $user_input[$key] = $value;
        }
        $this->log($post_data, $user_input);
    	...
    

    All CF7 hooks are skipped like this. CF7 does the following in their WPCF7_Submission class:

    
    private function setup_posted_data() {
    $posted_data = (array) $_POST;
    $posted_data = array_diff_key( $posted_data, array( '_wpnonce' => '' ) );
    $posted_data = $this->sanitize_posted_data( $posted_data );
    
    $tags = $this->contact_form->scan_form_tags();
    
    foreach ( (array) $tags as $tag ) {
    	if ( empty( $tag['name'] ) ) {
    		continue;
    	}
    
    	$name = $tag['name'];
    	$value = '';
    
    	if ( isset( $posted_data[$name] ) ) {
    		$value = $posted_data[$name];
    	}
    
    	$pipes = $tag['pipes'];
    
    	if ( WPCF7_USE_PIPE
    	&& $pipes instanceof WPCF7_Pipes
    	&& ! $pipes->zero() ) {
    		if ( is_array( $value) ) {
    			$new_value = array();
    
    			foreach ( $value as $v ) {
    				$new_value[] = $pipes->do_pipe( wp_unslash( $v ) );
    			}
    
    			$value = $new_value;
    		} else {
    			$value = $pipes->do_pipe( wp_unslash( $value ) );
    		}
    	}
    
    	$posted_data[$name] = $value;
    }
    
    $this->posted_data = apply_filters( 'wpcf7_posted_data', $posted_data );
    
    return $this->posted_data;
    }
    

    Wouldn’t something similar be a better way to get all the data? For instance:

    
    $submission = WPCF7_Submission::get_instance($form_obj, ['skip_mail' => true]);
    
    $posted_data = $submission->get_posted_data();
    
    • This reply was modified 6 years, 10 months ago by absolutist.
    Thread Starter absolutist

    (@absolutist)

    Sorry, I totally got that wrong. You can get the posted data, with all the filters applied, by using:

    
    $submission = WPCF7_Submission::get_instance();
    $user_data = $submission->get_posted_data();
    

    It would be great of that could be implemented.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Error when not using your-email or your-name fields’ is closed to new replies.