Tag Archives: database

Controlling Input with Mootools Javascript

On a project that I was recently working on, I had a series of text input boxes that I wanted to be numeric only fields. I have my PHP form validation to check that the data is numeric before entering any information in to the database, and I always use mysql_real_escape_string() on the data I am saving. But to save loat time and page refreshed, I decided to add some extra validation with the Mootools javascript library which I am using trough out the site already.

View Example

Update to Numbers Array

I have updated the Numbers array to include the number pad on full size keyboards.

Allowing Numbers:

Because I have a bunch of inputs that I need validated, I decided that I would assign each input with a matching class, then Scan the page for that class with my Javascript, then only allow specific key codes to be entered.

Your Age...

Inside of my DOM Ready state, I run this simple code.

window.addEvent('domready', function() {
	var numbers = [8, 48,49, 50, 51,52,53,54,55,56,96,97,98,99,100,101,102,103,104,105];
	$$('.numeric').each(function(item) {
		item.addEvent('keydown', function(key) {
			for (i = 0; i < numbers.length; i++) {
				if(numbers[i] == key.code) {
					return true;
				}
			}
			return false;
		});
	});
});

If you can see the line I have specified only the Key Codes that are allows, I have allowed for numeric numbers and the Delete Key.

	var numbers = [8, 48,49, 50, 51,52,53,54,55,56,96,97,98,99,100,101,102,103,104,105];

Other Uses:

You could disallow any key entry, This isnt a great idea, but could be used when maybe using an overlay, or special effect.

window.addEvent('domready', function() {
	window.addEvent('keydown', function() {  return false; });
});

Dissallowing Keys:

You could simply reverse this function, to block a small amount of keys rather than just allowing some, it would be as simple as changing the locations of your return true/false statements.

This example would allow anything except numbers.

window.addEvent('domready', function() {
	var numbers = [48,49, 50, 51,52,53,54,55,56,96,97,98,99,100,101,102,103,104,105];
	$$('.numeric').each(function(item) {
		item.addEvent('keydown', function(key) {
			for (i = 0; i < numbers.length; i++) {
				if(numbers[i] == key.code) {
					return false;
				}
			}
			return true;
		});
	});
});

Building a Completely Dynamic site using text files, PHP and no mySQL.

I spent a fair amount of time trying to help people on PHP forums such as webdeveloper.com : Sheldon and one thing I see on a regular basis is over complex systems for basic site structures with people who at this stage don’t have enough knowledge of PHP to build a secure structure.

Now don’t get me wrong, their not stupid, and I’m for sure not the greatest !

So, tonight, a sunday evening, nothing on the tele, and less of a social life lately it seams. I have spent 2 hours building a completely dynamic flat file web structure.

I built this for a couple of reasons, I have never built a system using a complete class that I have written from line 1. I have worked with classes, and extended classes, but never started from scratch. It was something to do, and.. It could be helpful to others, and that how I roll, I like to help out.

  • Flat file pages
  • Small footprint < 12k
  • No mySQL/ database needed
  • Simple integration
  • Customisable template design
  • Runs on Apache and IIS Severs
  • Supports Apache Mod ReWrite URLs
  • Secure againsts including ‘Bad Files’

Installation:

1:Drop it in the directory you wish to run the system.

2:Customise the ‘index.php’ file with your own HTML, making sure you keep the PHP.

3:Open ./includes/simpleSite.inc’, find the function ‘config()’ and check that all of the ‘$config[]‘ array values are correct. They should be 99% dynamic.

This uses a class to construct the functions, so required a late version of PHP 4, but PHP 5 is better If your current web host doesnt offer up to date software contact me via my web design & hosting business Inbox Design

This is offered as is, I am happy to help out with installing and custimizing the design, If you have any bugs or feature requests, just ask :)

Free Download: [download#2] -> simpleSitev0.2.zip (Update v0.2)

Free Download: [download#1] -> simpleSitev0.1.zip