diff --git a/content/underskriftskampanje/medisinsk-cannabis-pa-resept/10-form.en.php b/content/underskriftskampanje/medisinsk-cannabis-pa-resept/10-form.en.php
index f68680c..a1319be 100644
--- a/content/underskriftskampanje/medisinsk-cannabis-pa-resept/10-form.en.php
+++ b/content/underskriftskampanje/medisinsk-cannabis-pa-resept/10-form.en.php
@@ -1,4 +1,4 @@
-
Show your support by signing here
+Show your support by signing here
= $petition_form ?? '' ?>
= $petition_signatures ?? '' ?>
diff --git a/content/underskriftskampanje/medisinsk-cannabis-pa-resept/10-form.php b/content/underskriftskampanje/medisinsk-cannabis-pa-resept/10-form.php
index d6a4950..f5de520 100644
--- a/content/underskriftskampanje/medisinsk-cannabis-pa-resept/10-form.php
+++ b/content/underskriftskampanje/medisinsk-cannabis-pa-resept/10-form.php
@@ -1,4 +1,4 @@
-Signer her for å vise din støtte
+Signer her for å vise din støtte
= $petition_form ?? '' ?>
= $petition_signatures ?? '' ?>
diff --git a/custom/plugins/page/petition-form.php b/custom/plugins/page/petition-form.php
index cdde2a1..b54f91b 100644
--- a/custom/plugins/page/petition-form.php
+++ b/custom/plugins/page/petition-form.php
@@ -42,6 +42,61 @@ function petitionSanitizeCSV(string $value): string {
return $value;
}
+/**
+ * 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 {
+ $configPath = dirname(__DIR__, 2) . '/listmonk-config.php';
+ if (!file_exists($configPath)) {
+ error_log("Listmonk config not found: {$configPath}");
+ return false;
+ }
+
+ $config = require $configPath;
+ if (!$config['enabled']) {
+ error_log("Listmonk disabled in config");
+ return false;
+ }
+
+ // Log the UUIDs being used
+ error_log("Listmonk attempting subscription with UUIDs: " . implode(', ', $config['list_uuids']));
+
+ $payload = json_encode([
+ 'email' => $email,
+ 'name' => $name,
+ 'list_uuids' => $config['list_uuids']
+ ]);
+
+ $url = $config['url'] . '/api/public/subscription';
+ $ch = curl_init($url);
+ curl_setopt_array($ch, [
+ CURLOPT_POST => true,
+ CURLOPT_POSTFIELDS => $payload,
+ CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_TIMEOUT => 10
+ ]);
+
+ $response = curl_exec($ch);
+ $curlError = curl_error($ch);
+ $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ curl_close($ch);
+
+ if ($curlError) {
+ error_log("Listmonk curl error: {$curlError}");
+ return false;
+ }
+
+ if ($httpCode < 200 || $httpCode >= 300) {
+ error_log("Listmonk subscription failed: HTTP {$httpCode}, URL: {$url}, Response: {$response}");
+ return false;
+ }
+
+ error_log("Listmonk subscription success for {$email}");
+ return true;
+}
+
/**
* Check IP-based rate limiting to prevent email bombing and spam
* Returns true if IP is allowed, false if rate limit exceeded
@@ -193,15 +248,15 @@ function petitionGetCsvPath(string $petitionId): string {
function petitionGetIdFromPath(string $pageDir): ?string {
// Get the last directory segment as the petition ID
$petitionSlug = basename($pageDir);
-
+
// Sanitize: remove any leading numeric prefix (e.g., "01-" becomes just the slug part)
// This handles folders like "01-my-petition" -> "my-petition"
$petitionSlug = preg_replace('/^\d+-/', '', $petitionSlug);
-
+
if (empty($petitionSlug)) {
return null;
}
-
+
return $petitionSlug;
}
@@ -795,7 +850,7 @@ function petitionRenderForm(Context $ctx, array $formData, array $errors, bool $
$currentTime = time();
$regions = petitionGetRegions($ctx);
- $html = '