Monday, January 18, 2010

BWT Simple PHP Contact Form

Just got done putting together a very simple form available for download that I decided to call BWT Simple PHP Contact Form. Simple name for a simple script.

BWT Simple PHP Contact Form as the name states is a simple contact form that can be implemented into any website, on any server that is running PHP5+.

All form validation is check by the server and contains no JavaScript and is written in the form of Object Oriented Programming (OOP).

That's about it really.

Please feel free to download the script and give it a go.

Click here to download

- Pete

Saturday, January 16, 2010

Simple OOP Form with PHP

Let's face it, as a developer, you WILL have to do some playing with PHP. It's just a matter of time and if you can't stand the language, you're gonna have to just deal with it. As PHP is still one of the most widely used server-side languages today, it's juts best to learn the language, and learn it the right way.

Now, when I say the right way, I mean, by using programming best practices as stated in my last blog about UML, MVC and OOP. This blog is about OOP in general and why it is the best and cleanest way to program your applications.

Below is a very simple example of PHP OOP and forms:

The PHP the class:
class HelloClass
public function sayHello($obj)
echo $say_hello = "Hello there " . $this->hello_name;
return say_hello;

<form action="" name="hello_form" method="post">
Enter your name:<br/>
<input type="text" name="hello_name" value="" /><br/>
<input type="submit" name="hello_submit" value="Say Hello"/>
<input type="hidden" name="hello" value="true"/>

Define the objects:
$obj = new HelloClass;
$obj->hello_name = $_POST['hello_name'];
$obj->hello = $_POST['hello'];

The results:
Hello there "Name that was entered"
Ex: Hello there Pete

I know the code might be a bit messy on Blogger but feel free to download this example here.

- Pete

Friday, January 8, 2010

OOP, UML and MVC, What? and Why?

As a developer, there comes a time when you start to get deeper and deeper into learning new ways of writing and structuring your code. I've been doing TONS of research and playing around with some techniques that are of coarse well known but to be honest I'm not exactly sure who really uses them, at least and unfortunately many co-workers are quite clueless when it comes to these techniques.

The techniques that I am referring to are OOP (Object Oriented Programming), UML (Unified Modeling Language) and MVC (Model View Controller) which is basically a way to organize your stuff in a manner that you should already be doing in the first place.

First off, OOP. I can't be the only one that had a tad of trouble getting their foot into the door and actually understand what on earth this was and why it is so important when developing basically anything and everything from simple show a name applications to more complex applications where there are many functions firing off at the same time.

OOP is a beast and once you get it, you know because it hits you like a train, making you think, OMG I can do this and yes, yes I do understand it.

At first I began writing some functions thinking I was writing OOP even though all I was doing was creating a bunch of functions and firing a main function instead of creating any classes which means I was still technically writing procedural code, yucky.

But that one day came and I got hit by that train that made me say, Oh jeez I was doing this all wrong but thankfully I get it now and will continue to do it the right way.

Now for UML. This isn't exactly all that new to me in a sense because when I was handed a project I always always always created a simple diagram which included needed functions, database tables with row names, foreign keys and so on.

Thing is, I'm not sure anyone even uses this technique to build their applications and by all means if you do please let me know.

Finally MVC which let's be honest, you should be doing this technique no matter what because it makes sense. Like OOP, there are many developers that might have trouble understanding what this is and why they should really even bother with it. The truth is that you should and it helps greatly when applications start to get larger in scale and you need to scale your application with ease and ridden the possibilities of introducing big nasty bugs into them.

But what is MVC? It's simply a way to slice up the code for your application into sections that make sense. Model, View and Controller, which should be obvious of what they do but instead of me trying to explain it all, try reading the Wiki on it here...

Enough of my ramble, I plan on tossing up a few examples of some OOP concepts in some future blogs in a few different programming languages.

- Pete