Add per-form Listmonk list UUIDs to newsletter plugin
Add support for specifying Listmonk list UUIDs per form instance Update petition form to use metadata-defined UUIDs Add success confirmation message to newsletter forms Update documentation with new functionality
This commit is contained in:
parent
15a8f97cb2
commit
36591e7438
5 changed files with 47 additions and 17 deletions
|
|
@ -46,7 +46,7 @@ function petitionSanitizeCSV(string $value): string {
|
|||
* Subscribe email to Listmonk newsletter lists via public API
|
||||
* Listmonk handles double opt-in (sends its own confirmation email)
|
||||
*/
|
||||
function petitionSubscribeToNewsletter(string $email, string $name): bool {
|
||||
function petitionSubscribeToNewsletter(string $email, string $name, array $listUuids = []): bool {
|
||||
$configPath = dirname(__DIR__, 2) . '/listmonk-config.php';
|
||||
if (!file_exists($configPath)) {
|
||||
error_log("Listmonk config not found: {$configPath}");
|
||||
|
|
@ -59,13 +59,15 @@ function petitionSubscribeToNewsletter(string $email, string $name): bool {
|
|||
return false;
|
||||
}
|
||||
|
||||
$uuids = !empty($listUuids) ? $listUuids : $config['list_uuids'];
|
||||
|
||||
// Log the UUIDs being used
|
||||
error_log("Listmonk attempting subscription with UUIDs: " . implode(', ', $config['list_uuids']));
|
||||
error_log("Listmonk attempting subscription with UUIDs: " . implode(', ', $uuids));
|
||||
|
||||
$payload = json_encode([
|
||||
'email' => $email,
|
||||
'name' => $name,
|
||||
'list_uuids' => $config['list_uuids']
|
||||
'list_uuids' => $uuids
|
||||
]);
|
||||
|
||||
$url = $config['url'] . '/api/public/subscription';
|
||||
|
|
@ -1238,6 +1240,9 @@ function petitionGetPageData(?Context $ctx): ?array {
|
|||
// Use petition_title if set (for subpages), otherwise fall back to page title
|
||||
$petitionTitle = $metadata['petition_title'] ?? $metadata['title'] ?? $petitionId;
|
||||
$thankYouPage = $metadata['thank_you_page'] ?? 'takk';
|
||||
$newsletterListUuids = !empty($metadata['newsletter_list_uuids'])
|
||||
? array_map('trim', explode(',', $metadata['newsletter_list_uuids']))
|
||||
: [];
|
||||
|
||||
$formErrors = [];
|
||||
$formData = ['firstname' => '', 'surname' => '', 'email' => '', 'region' => '', 'display' => 'semi'];
|
||||
|
|
@ -1472,7 +1477,7 @@ function petitionGetPageData(?Context $ctx): ?array {
|
|||
error_log("Newsletter checkbox: " . ($newsletterOptIn ? 'checked' : 'not checked'));
|
||||
if ($newsletterOptIn) {
|
||||
$fullName = $formData['firstname'] . ' ' . $formData['surname'];
|
||||
petitionSubscribeToNewsletter($formData['email'], $fullName);
|
||||
petitionSubscribeToNewsletter($formData['email'], $fullName, $newsletterListUuids);
|
||||
}
|
||||
|
||||
$_SESSION['last_petition_submit'] = time();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue