Archive for the ‘Web’ Category

Dr Martens For Life Microsite

Sunday, March 15th, 2009

Haven’t updated the blog for a while so I thought I would create a few posts on what I have been up to in the early stages of 2009!

Back in February, I developed a microsite for Dr Martens, named ‘Dr Martens For Life’. The whole idea behind the site is to activate your guarantee for your Dr Martens Boots / Shoes for life!

Dr Martens For Life Microsite

Using CakePHP, I did some lovely custom validation to check if a guarantee code was valid (from a list of codes in a MySQL table) and also to see if it had not been redeemed before (only one code per product).

Take a look, if you fancy buying a pair of Dr Martens - take a look here too.

shhh.tv

Tuesday, December 23rd, 2008

Looking for a special gift for someone but cannot think of what?

Well shhh.tv is here to sort that!! simply, answer a few questions and generate a gift for a friend or foe… its a shhhhhecret!

shhh.tv screenshot

shhh.tv is a MAKE project for LOVE.

I am proud to say that I built the ‘back-end’ of the site…. ooooh err, using the CakePHP framework, MySQL and AMFPHP.

Enjoy and Merry Christmas!

Green Santa

Friday, December 12th, 2008

Green Santa: Your Santa Needs YOU

Been really busy at LOVE for the last couple of weeks (well all year to be honest!), working on numerous websites including the lovely Green Santa website.

Taken from the LOVE blog post: “The basic premise of Green Santa is simple:
Global warming is causing Santa’s runway to melt.
If Santa’s runway melts, his sleigh can’t take off.
If his sleigh can’t take off, he can’t deliver your Christmas presents.
So if you want your presents this year, you’ll need to do your bit for the environment first.”

There is also a Green Santa Facebook Application, if your a facebook user - please add the application to receive the lastest breaking news to your profile!

Visit Green Santa and make a pledge!

Custom Validation Rules in CakePHP 1.2

Thursday, November 6th, 2008

CakePHP’s validation class is pretty powerful, however there may be a time when you require a validation method that hasn’t been defined, this is where custom validation rules fit in.

Lets imagine you have a select box containing a users ‘title’ field in a form. You also have a ‘other_title’ text field which must be filled in if the ‘Other’ value is selected.

How would you go about validating this?

Simple: In your Model specify your validation criteria as so…

var $validate = array(
'title' => array(
'rule' => array('minLength',1),
'message' => 'Please select your title'
),
'other_title' => array(
'rule' => array('_compareFields', 'title', 'other'),
'message' => 'Please enter your other title'
)
);

As you can see when the Model validates, the ‘other_title’ field is validated against a custom rule named ‘_compareFields’ parsing in ‘title’ and ‘other’ as parameters.

‘title’ is the field to compare ‘title_other’ with and ‘other’ is the compare value that I am matching on.
Therefore the custom rule looks like:

function _compareFields($field=array(), $compare_field, $compare_value){
if(!empty($this->data[$this->name][$compare_field])&&(strtolower($this->data[$this->name][$compare_field]) == strtolower($compare_value))) {
$field_value = array_shift($field);
if(!empty($field_value)) {
return true;
} else {
return false;
}
} else {
return true;
}
}

I could of simply used ‘Other’ as the $compare_value but I like writing generic functions that can be re-used multiple times. This function will now cater for other fields with different $compare_fields and the ‘case’ of this value is not sensitive in the view.

Hope that helps someone out there!

Mark Holt

This is the blog of Mark Holt, a Manchester based web developer currently working for LOVE.


Search

You are currently browsing the archives for the Web category.


Categories