Using the CakePHP 1.2 Email component

I was following the documentation at

about sending an email with CakePHP using the Email component, used the sample code they provided but could not get my application to send email. A little bit of googling helped me figure out what was going on. I have CakePHP setup within my XAMPP htdocs directory and my MercuryMail server was not started. You need to have a mail server setup to be able to send email and there are a few more steps you need to do as well to get up and running. It’s beautifully summarized here:

Once your Mercury is properly setup, you are good to send emails from CakePHP!!!

Lesson learned i guess!

Hope It Helps!

Validating a checkbox in CakePHP 1.2

I was looking for a good way to validate a checkbox for a site i was working on, and came upon this link that pointed me in the right direction:

I followed the instruction, mainly:

'agree' => array(
'rule' => array('comparison', '!=', 0),
'required' => true,
'message' => 'You must agree to the terms of use',
'on' => 'create'

But for some reason, it would not work for me no matter what i tried, my checkbox still failed validation, even when the box was checked. I narrowed down the problem to the:

'required' => true,

line. It seemed to break the validation for a reason I do not know. So removing this line should get you through the validation correctly. I did my validation another way by using a new CakePHP core validation function, inList. Here is the code i use to account for all possible values i am expecting my checkbox to have when checked. I added it to the necessary model class:

'rule' => array('inList', array('1',1,'true', true,'on')),
'message' => 'You need to accept the Terms Of Use to be able to register.')

As you can see, the ‘inList’ validation will check to see if the checkbox value is within the array values submitted so you can account for all possible values you need your checkboxes to have to pass validation. This will improve reusability within your code.

Hope It Helps.