Waldemar
Waldemar

Reputation: 115

Contact Form 7 - How to hide email field in source code / development tools properly?

I'm looking for a way to hide the email adress of the post owner in a contact form 7 formular.

It works fine to pass the value dynamically by default shortcode attributes (https://contactform7.com/getting-default-values-from-shortcode-attributes/) or with the modules plugin (https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/) and I'm also able to hide the field. The second plugin has also the 'obfuscate' functionality. But it obfuscates only the mail in the source code, not in the development tools.

Edit: Our website is a classified plattform. Every post has an owner and the customers are able to contact the owner by contact form. I wanted to populate the value of the "hidden" field with the value of the owner-email and use this value in the "To" part. The population works really fine, but the owner email is in the code of the page and everyone with some IT skills is able to see them. I would like to hide this value. Pipes are great, but I'm not able to use following code for the pipes. The values are not populated to the dropdown list:

echo do_shortcode('[contact-form-7 id="635" title="Contactform1" destination-email="Ownermail|'.get_post_meta( $post_id, "owner_email", true ).'"]'); ?>

Any Ideas?

Thanks + Regards, Waldemar

Upvotes: 1

Views: 3468

Answers (1)

mmm
mmm

Reputation: 1155

to send a e-mail to the post author, first set the form recipient to [recipientEMail]

and then use this code to set the value to the e-mail

add_filter("wpcf7_posted_data", function ($wpcf7_posted_data) {


    if ("15896" === $wpcf7_posted_data["_wpcf7"]) { // test the contact form id

        $post = get_post($wpcf7_posted_data["_wpcf7_container_post"]);
        $post_author = get_userdata($post->post_author);

        $wpcf7_posted_data["recipientEMail"] = $post_author->user_email;

    }


    return $wpcf7_posted_data;

});

Upvotes: 2

Related Questions