Use text file to update text on Sign In Page (or other pages)

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Use text file to update text on Sign In Page (or other pages)

Post by shasta59 » 2016-02-15 19:16

Using Appgini 5.50

Have you ever wanted to use a text file to update the text on the main page of your app? This is the page where you log in or can sign Up. There is that area on the left side in which you can put customized splash content here.

Well using the following code, placed at the bottom of the login.php page you can do it.
Okay, why? Well there are times I cannot update the page for the client and I sure as heck do not want him playing in the files or even having access to the core files. So I allow him/her to create a txt file and put what they want to say in that file then they can upload it to a specific location. The script then reads the file and puts that text in the element.

I do include instructions to the client on how to add some basic html tags to bold, using headings etc. But lets get to the meat of this tip.

Step 1: (add the following to login.php)

At the bottom of the page, just after the last </div> insert the following

Code: Select all

<script>
document.observe('dom:loaded', function loadfile() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      document.getElementById('login_splash').innerHTML = xhttp.responseText;
    }
  };
  xhttp.open("GET", "yourfile.txt", true);
  xhttp.send();
})
</script>
It is important it goes above the existing script file which has a .focus in it.

Here are some explanations of the above:
  • document.observe('dom:loaded' - this ensures it runs only when the page is loaded
    document.getElementById('login_splash') - this selects the element - the login_splash div
    xhttp.open("GET", "yourfile.txt", true); - this gets and reads the text file with the info you want displayed. You can name this whatever you wish
Step 2: create the text file

It must be a plain text file. Use a basic text editor to create this file.
Place the text file where you want in the folder or even another location on the server
Give your client ftp access to only the folder where you want him to place the file.
*IMPORTANT* - ensure the client knows what name to give the file and to make sure, when uploading, it overwrites the older file.

Okay that should work for you.

Now, features you can add but not shown here.

Code to check to make sure file is present and if not it can go to another location to get the base file. (I call this client screw up protection).
Code to select different files based upon the season. Christmas, New Years, Valentine's day etc. This allows for having custom files which reflect a holiday or season greeting

You can also use this same method to show text on the membership signup page. Maybe, based upon a date you do not want anyone else to sign up. You can use date/time checking in your code to change the message or file selection to advise of this. You can also then have your code hide the signup button to prevent signups.

(Yes, if they manually go to signup page, if they know the URL, they could sign up. But I have code which also changes the allowSignup flag in membership_groups in the database to prevent this.

Hope someone finds this useful.

Any issues let me know. Make sure you include the version you are using at the top of your message - first line is best.

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

User avatar
pilandros
Veteran Member
Posts: 57
Joined: 2014-02-13 18:19

Re: Use text file to update text on Sign In Page (or other pages)

Post by pilandros » 2016-12-27 23:38

Thank you Alan,
This is a very easy, nice & useful piece of coding you shared with all of us.
On behalf of the community we appreciate your posting.
Cheers.

Post Reply