• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: How to set a form to auto unpublish or 'expire'

How to set a form to auto unpublish or 'expire' 9 months 1 week ago #42865

  • a2zcs
  • a2zcs's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 28
Is there a way that we can set a form to stop taking submissions at a certain date and time?
The administrator has disabled public write access.

How to set a form to auto unpublish or 'expire' 9 months 4 days ago #42876

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 216
  • Thank you received: 57
You can do it with javascript and a hidden field 'expiryDate' to contain the date that the form should expire. Her's some code to show a notification and a message under the disabled submit button
First create the hidden field and add a date in the past for testing like 2023-06-30

Next add the following javascript to the css/javascript section
<script>
document.addEventListener('DOMContentLoaded', function() {
  var expiryDateField = document.querySelector('input[name="form[expiryDate]"]');
  var expiryDate = expiryDateField.value;
 
  // Convert the expiryDate to a JavaScript Date object
  var expiryDateTime = new Date(expiryDate);
 
  // Get the current date
  var currentDate = new Date();
 
  // Disable the submit button and show the expired message if the form has expired
  if (currentDate > expiryDateTime) {
    var submitButton = document.querySelector('button#submit');
    if (submitButton) {
      submitButton.disabled = true;
      submitButton.style.cursor = "not-allowed"; // Apply the 'not-allowed' cursor style to the disabled submit button
 
      // Show the custom notification about the expired form
      var alertMessage = 'Sorry, this form has expired and is no longer accepting submissions.';
      showNotification(alertMessage);
 
      // Automatically close the custom notification after 5 seconds
      var notificationTimeout = 3000; // 3 seconds
      setTimeout(function() {
        hideNotification(); // Call the hideNotification function to remove the notification
      }, notificationTimeout);
    }
  }
});
 
function showNotification(message) {
  // Create the notification overlay
  var notificationOverlay = document.createElement('div');
  notificationOverlay.className = 'notification-overlay';
  document.body.appendChild(notificationOverlay);
 
  // Create the notification
  var notificationDiv = document.createElement('div');
  notificationDiv.className = 'notification';
  notificationDiv.innerHTML = '<p>' + message + '</p>';
  document.body.appendChild(notificationDiv);
 
  // Show the notification overlay
  notificationOverlay.style.display = 'block';
}
 
function hideNotification() {
  // Hide the notification and overlay
  var notificationOverlay = document.querySelector('.notification-overlay');
  var notificationDiv = document.querySelector('.notification');
  if (notificationOverlay) {
    document.body.removeChild(notificationOverlay);
  }
  if (notificationDiv) {
    document.body.removeChild(notificationDiv);
  }
}
</script>

Do check the submit button reference as it might be different in your form. Then you'll need some css to go with this
<style>
.notification-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6); /* Semi-transparent black overlay */
  z-index: 9999; /* Higher z-index than the content, so it appears above the content */
}
 
.notification {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
  border: 2px solid #f00;
  padding: 10px;
  z-index: 10000;
}
</style>
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.

How to set a form to auto unpublish or 'expire' 9 months 3 days ago #42878

  • a2zcs
  • a2zcs's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 28
Thank you for that, but I'm not getting any results.
When you said to check the Submit Button reference, I assume you were talking about each occurrence of "submitButton"
I replaced each of those with just "Submit" which is the name of the Submit button

Obviously I did something wrong. Please advise
The administrator has disabled public write access.

How to set a form to auto unpublish or 'expire' 9 months 4 days ago #42879

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 216
  • Thank you received: 57
I was refering to the line which declares the variable submitButton, this one
var submitButton = document.querySelector('button#submit');
in the form i used the button is named 'submit' so if in your form it is called for example 'send' you would change the line to
var submitButton = document.querySelector('button#send');
If your button is called Submit (capital S} then it should be as below because button#submit and button#Submit are not the same thing
var submitButton = document.querySelector('button#Submit');
Don't forget the hidden field either...... B)
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 9 months 4 days ago by iceferret.
The administrator has disabled public write access.

How to set a form to auto unpublish or 'expire' 9 months 3 days ago #42883

  • a2zcs
  • a2zcs's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 28
Ok, great, that worked. How would I also specify a time of day for the form to expire?
The administrator has disabled public write access.

How to set a form to auto unpublish or 'expire' 9 months 2 days ago #42884

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 216
  • Thank you received: 57
If you enter 2023-06-30T12:00:00 into the hidden field that should give the equivalent of midday on June 30th 2023, the T is a delimiter
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.
The following user(s) said Thank You: a2zcs
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!