Disable pasting email confirmation

By: Roberto Alvarez | Asked: 04/14/2022
ForumsCategory: How-toDisable pasting email confirmation
Roberto Alvarez asked 2 years ago

Hi,

How I can disable pasting into email confirmation?

I need to prevent that the user copy & paste the email with errors.

https://espejo.logos.cl/portafolio/correccion/corrector-de-portafolios/formulario-de-postulacion-corrector-de-portafolio/

Best regards.

Walter JonesWalter Jones replied 2 years ago

Could you clarify? I am not sure why someone would be pasting in a email notification?

Roberto Alvarez replied 2 years ago

Is not email notification is into the field "email confirmation", the user can copy the wrong email and paste into "email confirmation".

2 Answers
Best Answer
Victor Font answered 2 years ago

You have to do this with JavaScript. Try this snippet:

document.getElementById("field_conf_29yf4d2").addEventListener('paste', e => e.preventDefault());

document.getElementById("field_conf_29yf4d2").addEventListener('drop', e => e.preventDefault());

document.getElementById("field_conf_29yf4d2").addEventListener('autocomplete', e => e.preventDefault());

I tested this in my development environment. It works for paste and drag and drop. I didn't test autocomplete, but have no reason to believe it won't work.

Change "field_conf_29yf4d2" to the input id of your email confirmation field.

Victor Font replied 2 years ago

Don't forget to wrap the JavaScript in the script tags. This forum removes them from the display. Also, add the JavaScript to the after fields area of your form's Customize HTML page.

Roberto Alvarez replied 2 years ago

Thanks 😉 , It worked perfectly.

Walter JonesWalter Jones answered 2 years ago

@RobL from the slack group pasted this snippit a few weeks ago related to sending emails to all registered users or a particular access level in wordpress (admin, etc). You may could modify this for sending your e-mails if all of the users are registered on your wordpress and have the same access level:

add_shortcode('notificationtargets', 'getNotificationList');

function getNotificationList($atts) {

$eventType = $atts["eventtype"];

$notificationType = $atts["notificationtype"];

$addresses = array();

// fill addresses array ...

$roleArray = array( 'author', 'subscriber' ); // whatever role(s) you want

$users = get_users( array( 'role__in' => $roleArray ) );

foreach ( $users as $user ) {

$addresses[] = $user->user_email;

}

if ($notificationType == "EMAIL") {

$addressCSV = implode(",", $addresses);

return $addressCSV;

}

}

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right