[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH][DB] Surveys: add redirect URL option after survey completion

"luci \(@luciash\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <69f1dac63d8d2_3818f664419b2@gitlab-sidekiq-low-urgency-cpu-bound-v2-798fcb964d-gfkbm.mail>

luci pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
a65b0663 by NasserNgandu at 2026-04-29T10:00:26+00:00
[ENH][DB] Surveys: add redirect URL option after survey completion

Allow admins to specify a wiki page name or full URL to redirect users
to after completing a survey. When left empty, the existing behavior
(redirect to survey list) is preserved.
Input validation prevents invalid values in the redirect field.

- - - - -


6 changed files:

- db/tiki.sql
- + installer/schema/20260331_survey_redirect_after_tiki.sql
- lib/surveys/surveylib.php
- templates/tiki-admin_surveys.tpl
- tiki-admin_surveys.php
- tiki-take_survey.php


Changes:

=====================================
db/tiki.sql
=====================================
@@ -2437,6 +2437,7 @@ CREATE TABLE `tiki_surveys` (
   `lastTaken` int(14) default NULL,
   `created` int(14) default NULL,
   `status` char(1) default NULL,
+  `redirect_after` varchar(255) default NULL,
   PRIMARY KEY (`surveyId`)
 ) ENGINE=MyISAM AUTO_INCREMENT=1 ;
 


=====================================
installer/schema/20260331_survey_redirect_after_tiki.sql
=====================================
@@ -0,0 +1 @@
+ALTER TABLE `tiki_surveys` ADD COLUMN `redirect_after` varchar(255) default NULL;
\ No newline at end of file


=====================================
lib/surveys/surveylib.php
=====================================
@@ -199,13 +199,15 @@ class SurveyLib extends TikiLib
     }
 
     /**
-     * @param $surveyId
-     * @param $name
-     * @param $description
-     * @param $status
+     * @param int    $surveyId
+     * @param string $name
+     * @param string $description
+     * @param string $restriction
+     * @param string $status
+     * @param string $redirect_after URL or wiki page name to redirect to after survey completion
      * @return mixed
      */
-    public function replace_survey($surveyId, $name, $description, $restriction, $status)
+    public function replace_survey($surveyId, $name, $description, $restriction, $status, $redirect_after = '')
     {
         $newId = $this->surveysTable->insertOrUpdate(
             [
@@ -213,6 +215,7 @@ class SurveyLib extends TikiLib
                 'description' => $description,
                 'restriction' => $restriction,
                 'status' => $status,
+                'redirect_after' => $redirect_after,
             ],
             ['surveyId' => empty($surveyId) ? 0 : $surveyId]
         );


=====================================
templates/tiki-admin_surveys.tpl
=====================================
@@ -141,6 +141,13 @@
                     </select>
                 </div>
             </div>
+            <div class="tiki-form-group row">
+                <label for="redirect_after" class="col-sm-2 col-form-label">{tr}Redirect after completion{/tr}</label>
+                <div class="col-sm-10">
+                    <input type="text" name="redirect_after" id="redirect_after" class="form-control" value="{$info.redirect_after|escape}" placeholder="{tr}e.g. ThankYou or https://example.com/thanks{/tr}">
+                    <div class="form-text">{tr}Wiki page name or full URL to redirect to after survey completion. Leave empty to redirect to the survey list.{/tr}</div>
+                </div>
+            </div>
             <div class="tiki-form-group row">
                 <div class="col-sm-10 offset-sm-2">
                     <input type="submit" class="btn btn-primary" name="save" value="{tr}Save{/tr}">


=====================================
tiki-admin_surveys.php
=====================================
@@ -19,6 +19,7 @@ $inputConfiguration = [
             'description'           => 'xss',                //post
             'save'                  => 'alpha',              //post
             'status'                => 'alpha',              //post
+            'redirect_after'        => 'url',                //post
             'remove'                => 'int',                //post
             'find'                  => 'string',             //post
         ],
@@ -57,23 +58,45 @@ if (isset($_REQUEST["save"])) {
 
         $isUpdating = ! empty($_REQUEST["surveyId"]);
 
-        $sid = $srvlib->replace_survey($_REQUEST["surveyId"], $_REQUEST["name"], $_REQUEST["description"], $restriction, $_REQUEST["status"]);
-        if ($sid) {
-            if ($isUpdating) {
-                Feedback::success(tr('Survey updated successfully.'));
+        $redirect_after = isset($_REQUEST["redirect_after"]) ? trim($_REQUEST["redirect_after"]) : '';
+        // Validate redirect_after: only allow wiki page names (alphanumeric, spaces, dashes, underscores) or valid URLs
+        $redirect_after_valid = true;
+        if (! empty($redirect_after) && ! preg_match('#^https?://#', $redirect_after) && ! preg_match('/^[\w\s\-]+$/u', $redirect_after)) {
+            Feedback::error(
+                tr(
+                    'Invalid redirect value in the field "Redirect after completion". Please enter a wiki page name (letters, numbers, spaces, dashes) or a full URL starting with http:// or https://. Leave empty to redirect to the survey list.'
+                )
+            );
+            $redirect_after_valid = false;
+        }
+        if (! $redirect_after_valid) {
+            $cookietab = 2;
+        } else {
+            $sid = $srvlib->replace_survey(
+                $_REQUEST["surveyId"],
+                $_REQUEST["name"],
+                $_REQUEST["description"],
+                $restriction,
+                $_REQUEST["status"],
+                $redirect_after
+            );
+            if ($sid) {
+                if ($isUpdating) {
+                    Feedback::success(tr('Survey updated successfully.'));
+                } else {
+                    Feedback::success(tr('Survey created successfully.'));
+                }
+                $cat_type = 'survey';
+                $cat_objid = is_int($sid) ? $sid : $_REQUEST["surveyId"];
+                $cat_desc = substr($_REQUEST["description"], 0, 200);
+                $cat_name = $_REQUEST["name"];
+                $cat_href = "tiki-take_survey.php?surveyId=" . $cat_objid;
+                include_once("categorize.php");
+                $cookietab = 1;
+                $_REQUEST["surveyId"] = 0;
             } else {
-                Feedback::success(tr('Survey created successfully.'));
+                Feedback::error(tr('Failed to save survey.'));
             }
-            $cat_type = 'survey';
-            $cat_objid = is_int($sid) ? $sid : $_REQUEST["surveyId"];
-            $cat_desc = substr($_REQUEST["description"], 0, 200);
-            $cat_name = $_REQUEST["name"];
-            $cat_href = "tiki-take_survey.php?surveyId=" . $cat_objid;
-            include_once("categorize.php");
-            $cookietab = 1;
-            $_REQUEST["surveyId"] = 0;
-        } else {
-            Feedback::error(tr('Failed to save survey.'));
         }
     }
 }


=====================================
tiki-take_survey.php
=====================================
@@ -135,7 +135,16 @@ if (isset($_REQUEST["ans"])) {
         if (! empty($_REQUEST["vote"])) {
             $srvlib->add_survey_hit($_REQUEST["surveyId"]);
         }
-        header('Location: tiki-list_surveys.php');
+        if (! empty($survey_info['redirect_after'])) {
+            $redirect_url = $survey_info['redirect_after'];
+            // If it looks like a wiki page name (no protocol, no slash), build the wiki URL
+            if (! preg_match('#^https?://#', $redirect_url) && strpos($redirect_url, '/') === false) {
+                $redirect_url = 'tiki-index.php?page=' . urlencode($redirect_url);
+            }
+            header('Location: ' . $redirect_url);
+        } else {
+            header('Location: tiki-list_surveys.php');
+        }
         die;
     }
 }



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/a65b066305946842c967bbc925a27033e3c723b1

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/a65b066305946842c967bbc925a27033e3c723b1
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.