rpierce wrote: ↑2021-07-18 22:21
Once I figure out the code, which Hooks file would I include it in? My assumption is hooks/tablename - function tablename_header - case 'detailview'.
* Please note: for this article I did not create a "surveys" table but used an existing "employees" table. So, you will see "employees" here and there. Replace it by your specific table name.
Well, I guess you only want to deny insert if that user already has inserted once and not if she/he has entered the "add new" page without saving. So, we should
not change detail view in any case but
only after insert.
If it was my project, I'd start like this*:
Step 1: Create a "thank you page"
(1.1) You may create a custom page, for example
survey_inserted.php:
file: survey_inserted.php
Code: Select all
<?php
include("language.php");
include("lib.php");
include("header.php");
?>
<div class="alert alert-success">Thank you for taking the survey!</div>
<script>
window.localStorage.setItem(' ', ' ');
setTimeout(function() {
window.location.href = "index.php";
}, 5000);
</script>
<?
include("footer.php");
This code shows a success message, and saves a flag in localStorage. After 5 seconds user will be redirected to homepage (index.php).
Step 2: Change redirect after insert
Find the "Redirect after insert" value of your "surveys" table*:

- AppGini_0nmBBYs2nh.png (8.94 KiB) Viewed 4014 times
(2.1) Change that value like this:
Code: Select all
survey_inserted.php?SelectedID=#ID#
(2.2) regenerate (+upload) the generated files.
From now on, users will see the new custom "thank you" page after insert and will be redirected to homepage after 5 seconds.
Step 3: Deny filling another survey
Now we have a flag in localstorage which indicates that we have inserted a survey before. If user tries to enter surveys in "add new" mode, we can read the flag and deny editing.
(3.1) create
hooks/surveys-dv.js (or edit, if already exists):
file: hooks/surveys-dv.js
Code: Select all
redirectReturningUserTo("employees_view.php");
function redirectReturningUserTo(url) {
if (!jQuery("input[name='SelectedID']").val().length && window.localStorage.getItem(" ") != undefined) {
jQuery(".container > *").css("filter", "blur(5px) grayscale(1)");
setTimeout(function () { window.location.href = url; }, 100);
}
}
---
Test
(1) Insert a new survey (or enter the custom page manually):

- chrome_GPtB48Z7l0.png (3.75 KiB) Viewed 4014 times
You will see the "thank you message".

- RGYgYdbAJr.png (9.92 KiB) Viewed 4014 times
You will
not see the localStorage setting unless you check application tab in developer tools of your browser.
(2) Try to create a new survey*:

- W1k4gDOYYb.gif (250.18 KiB) Viewed 4014 times
Detail view in "Add new" mode will be blurred immediately and user will be redirected to Table View.
--
Additional notes and limitations
- The code shown here is a starting point for your own implementation
- Extension: You may also hide/remove the "add new" button in table view: create (or edit) hooks/surveys-tv.js, check existence of flag using .getItem function, then hide or remove element
Something like this (not tested) inside document.ready function of table-view-hook:
Code: Select all
if (window.localStorage.getItem(" ") != undefined) jQuery("#addNew").hide();
- According to your specs, this solution will work for one (single) survey-table. Just in case you will have more than one survey in the future (a table per survey), you will have to change the key when using localStorage.getItem and localStorage.setItem functions according to the specific table name.
- As mentioned in my previous post(s), this is not bulletproof and can be hacked easily if a user has little knowledge about javascript and browser settings. But according to your specification this should be fine with your secure intranet environment.