CakePHP Self Adjusting Credit Card Year

Posted October 18th, 2010 in CakePHP, PHP, Programming by Louie Miranda

When I used to program on PEAR, I’ve used the following code to auto-generate succeeding years.

$form->addElement('date', 'CCexpiry', 'Credit Card Expiration',
			  array('format' => 'F-Y',
					'minYear' => date('Y'),
					'maxYear' => date('Y') + 10));

Now, when I used CakePHP (1.2/1.3). They have a similar approach that we can all use.

<?php echo $this->Form->input('cc_expy',
              array('div' => false, 'label' => false, 'type' => 'date',
              'maxYear' => date('Y', strtotime('+ 7 years')),
              'minYear' => date('Y'),
              'dateFormat' => 'Y',
              'default' => date('Y'),
              'orderYear' => 'asc'
              )); ?>

CakePHP: Validate dependent field (select dropdown + input field)

Posted July 15th, 2010 in CakePHP, PHP, Programming, Projects by Louie Miranda

Earlier this week, I was working on a project where I needed to validate two dependent fields.

< ?php echo input('office', array('type' => 'select', 'options' => $nd[0])); ?>
< ?php echo input('office_other', array('maxlength' => '255', 'size' => '35', 'label' => 'Other Office')); ?>

The “office” field is a select (drop down box) from my data array(). What I needed is to be able to add another data from a field and name it as “office_other” where it would initially capture and re-list again new offices if it does not exist.

Continue Reading »