Okay, was able to piece this together looking at the plugin code. The documentation is not very helpful for this, unfortunately. It’s quite simple, so it would be nice if it were added.
As mentioned, we can hook into Forminator to get the info when the form is submitted. Then we can start a Newsletter subscription with this code. In the interest of completeness, I’m including the Forminator filter hook. However, the part inside the ‘foreach’ loop could be used anywhere.
function my_form_submit_field_data( $field_data_array, $form_id ) {
// iterate through submitted form array
foreach ($field_data_array as $k => $v) {
// do stuff to retreive info: $name and $email
$action='subscribe';
// instantiate the method
$newsletter = Newsletter::instance();
// check if newsletter user exists
$user = $newsletter->get_user($newslemail);
if (!$user) {
$user['name'] = $name;
$user['email'] = $email;
$user['status'] = 'C';
$user = $newsletter->save_user($user);
} else {
echo "User email already exists<br>";
}
}
return $field_data_array;
}
add_filter('forminator_custom_form_submit_field_data', 'my_form_submit_field_data', 10, 2);
-
This reply was modified 1 year, 2 months ago by jamminjames. Reason: added Forminator hook