Launch a Popup from functions.php

[ad_1]

Hello guys, I would really apreciaste some expertise as I am relatively new to wordpress.I build a form with WpForms, and I was asked to only allow one submission per person, I did that with Form Locker but it was not quite what was intended. The goal was to ask the person if they wanted to overwrite their submission with the current one and I’m lost on how to achieve that.

​

I have managed to overwrite all previous submissions that have the save email, but I’m not managing to device a way to ask the user permission for overwriting.

​

I have written this function to be able to detect previous submissions with the same email and delete them:

​

<?php

function remove_all_before_entry_save( $fields, $entry ) {

$email = $fields[8][‘value’];
//perform a query for all entries submitted on this form
$entries = wpforms()->entry->get_entries(
[
‘form_id’ => 9,
‘number’ => -1,
‘cap’ => false,
] );

foreach ( $entries as $_entry ){
$fields = json_decode($_entry->fields);
if($fields->{‘8’}->value===$email){
//confirmation section
wpforms()->entry->delete( $_entry->entry_id, [ ‘cap’ => false ] );
}
}
}
add_action( ‘wpforms_process_entry_save’, ‘remove_all_before_entry_save’, 9, 3 );
?>

&#x200B;

&#x200B;

Ideally in the ‘confirmation section’ I would launch a popup or something like that alerting that the user is already enrolled in X activity and ask if he would like to cancel previous enrollment and submit this one, if yes code would just proceed if not then terminate the execution before it reaches the wpforms()->entry->delete() method.

&#x200B;

Now, is there at all a way to achieve this in wordpress?

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer