Archive for the 'Uncategorized' Category

jquery form validation with cakephp model validation

I am currently working on a project in CakePHP and have used the jQuery form validation plugin from Jorn Zaefferer on other non-cake projects. So I had a thought… wouldn’t it be nice to do the field validation right from the cake model validation rules. So this is what I came up with.

[Warning Rough Draft!]

In my default layout I added the includes to load jQuery, jQuery Validate, and metadata. (Mine are inside an if condition that I activate on a per view basis, but this would be for application wide use.

echo $this->Html->script('jquery');
echo $this->Html->script('jquery-validate/jquery.validate.min');
echo $this->Html->script('jquery-validate/lib/jquery.metadata');

In the User model (/app/models/user.php) file I added a rule and made sure that it was working:

var $validate = array(
	    'firstName' => array(
	        'rule' => '/^[a-zA-Z\x27]{2,}$/i', //2 letters or '
	        'message' => 'First Name must only contain letters, and be at least two characters.'
	    'lastName' => array(
	        'rule' => '/^[a-zA-Z\x27]{2,}$/i', //2 letters or '
	        'message' => 'First Name must only contain letters, and be at least two characters.'

In the controller (/app/controllers/users_controller.php) I added the request handler componet. As well as the function ajax_validate. The function tries to create a new instance of the User model with the data provided. It then calls $this->User->validates() to see if it passes validation. If not the cake model error will be returned and added to the error label for user feedback.

var $helpers = array('Html','Ajax','Javascript'); //these are the helpers I am using
var $components = array('RequestHandler');

	function ajax_validate(){
		Configure::write('debug', 0); 
		$this->autoRender = false;
		$ret = "false";
		$this->data = $_GET['data'];
		if ($this->RequestHandler->isAjax()) {
		// If we have data, process it. If not send back an error.
				// $this->cleanUpFields();
				// Validate the User, if it's ok, show no errors. If not ok, show errors
				if ($this->User->validates()){
	                		$ret = true;
	            		} else {
	            			$errors = $this->User->invalidFields();
	            			// grab the error message from the array
	            			$ret = '';
	            			foreach($errors as $error){
	            				$ret .= $error;
			echo json_encode($ret);
		} else {
			echo 'not_ajax';

In the view (/app/views/users/index.ctp) I added the form validation jQuery initialization code as well as a form for the user to edit their settings. I am using the form meta plug-in to grab the validation rule out of the class parameter on the form field. So in the class, I add a remote remote:’users/ajax_validate’, so that jQuery will look to the controller function ajax_validate() to validate the field.

<div class="users form">
<?php echo $this->Form->create('User');?>
 		<legend><?php __('My Settings'); ?>Form->input('id');
		echo $this->Form->input('userName', array('label' => 'Username', 'disabled'=>'disabled'));// (not edit-able) 
		<?php echo $this->Form->input('firstName', array('class' => "{validate:{required:true,remote:'users/ajax_validate'}}"));?>
		<p class="subtle ml10 mbl1em">( your first name)</p>
		<?php echo $this->Form->input('lastName', array('class' => "{validate:{required:true,remote:'users/ajax_validate'}}")); ?>
		<p class="subtle ml10 mbl1em">( your last name)</p>
		<?php echo $form->submit('Save');?>

<?php //extra javascript for this view
echo $javascript->codeBlock('

$(document).ready(function() { 
    	onsubmit: false, //otherwise it will do all the remote calls when the user hits submit
    	meta: "validate"


Hope this is helpful to someone. Someday-maybe I’ll post an update when I clean it all up. A next step could be to handle the entire form onsubmit, but cake already does that with the model validation that we just added.



jQuery –
jQuery Form Validation and meta plugin:

Counting items with mysql and regex in the group by statement

Yesterday I needed to do a little report for the boss but the data that I needed to group together wasn’t exactly the same. I hit up the “Goog” for ways to use regular expressions in a count query, but that is kinda tricky to find so this is what I was able to come up with….

So let’s say you had a table where you were attaching the landing url a site visiting is entering your website on, and you wanted to track that landing url the whole way to the end of some web based procedure. Of course certain urls will be different but some could be common for the purpose of counting them together on a report. In a practical example, lets say you are doing pay-per-click traffic with Google and Yahoo. Both of these providers use unique ids in the url to help distinguish between multiple clicks from the same person (so you end up with many urls that are different but mean the same thing). And of course you were a good little developer when you decided to send Google traffic to /google/ and Yahoo to /yahoo/!
Continue reading ‘Counting items with mysql and regex in the group by statement’

And we are back.

So it has been quite some time since I posted on here.  It has been rough lately. Not sure what kind of funk I’ve been in… but actively trying to get out of it. Hoping getting back in tune with the tubes will help. (Twitter is probably the biggest reason not to post on here…damn you Twitter)

While I have been gone I have been doing some work with CakePHP, FAI – fully automatic linux installations, VirtualBox & VMware, Magento, etc. So I have been keeping pretty busy.

I also found a nice little hardware project that has just come into my radar. This is something that I have been wanting to work on in my *cough* free time. However my vision would be to use a host computer for all the logic and user control, and the controller board used for simple I/O. Anyone interested in this, drop a comment and let me know.

Happy Holidays from ProspectMX

The company I work for has decided to do a charity benefit of $10,000 in services to the organization that answers the question on their site or blog: “How can internet marketing benefit your organization?” For further details visit the post charity internet marketing

I hooked up my blog to twitter

Hey tweeple!

I am now a twitter fanatic. I avoided systems like this in the past, but recently have found great uses for it. So now I too, am a twitter-holic. So shout out to the tweeple!


Pic Programmer Schematics

Here are a few schematics that I have collected. Thought I would share these out there on the net. They all have pros and cons. You can read more about my specific experience with each one over here on the robot kits page.

Willem Pic Programmer Schematics

Tait Pic Programmer Schematics

JDM Pic Programmer Schematics

Classic Pic Programmer Schematics

Lancaster Linux User Group

Attention LUGers and LUGer-wannabes: I am helping reintroduce the Lancaster Linux User Group. With the rising cost of fuel, driving to the CPLUG meetings doesn’t fit everyone’s budget or busy schedule. So anyone who is interested, please visit the blog and post a comment stating your level of interest. I have spoken to several people already and feel that we could begin to form a great group in no time. BTW, we will plan on scheduling our meetings on a different day that the CPLUG does so that we do not create a conflict with their meetings.

Ahhh Ohhh, Web 2.0

So I added the glassy looking Web 2.0 icons to my sidebar the other day and was actually surprised of the result. Yesterday I ended up with a few extra twitter followers, a new facebook friend and I even had some decent stumbler action. Not bad for a few minutes of work. Of course I linked the icons to my profiles on those respective sites. This is the place I got the icons from if you are interested [].

I am not real big on all the social sites, and stay far far away from mysapce. Can you recommend any other sites worthy of holding a spot in my sidebar?

How I Use BlogExplosion

First off, let me say I have no affiliation with BlogExplosion and just a blogger who signed up on BlogExplosion.

Basically what I have been doing is surfing for traffic every couple of days so that I can spend 15 – 20 credits each day on traffic to my blog.
(Earn Blog Traffic -> Surf Member Blogs) I use Firefox and just pop this in a separate tab, and do other things while “surfing”. Also while surfing, I keep an eye out for interesting blogs and topics that are related to mine. When I find blogs like that, I post a comment. Sometimes they will let you do your site url when posting. This engages the other blogger. I also try to find a way to relate their post back to a post at my blog and refer them to what I have posted. So this creates extra traffic sources, unrelated to BlogExplosion itself.

Unless you have a blog with wide appeal and topic nature, it would seem like paying for a billboard ad in an unrelated space. Granted, the people who are all using this site all have blogs so some people will actually do what I do while surfing. Many of the visits I receive are people that just bounce from one blog to another. So the key here is to have content and “bait” if you will, as close to the top as possible on your blog so that when the people look to the surf bar, they see something to become engaged with. You are not going to capture everyone… but obviously the goal is as many as possible. Take a look at the top of my site [ ], and notice how I have my top area setup in such a way to be unique and personal. I wanted my site to be remembered and stand out from the crowd.

The other thing that I do is BlogRocket. Sometimes twice a day. For one credit you can get 4 – 10 visits rather then one. Also you can visit a site on the blog rocket page, to be entered into a credit contest. So if you do that once a day, you will have the best odds at winning that pool.

If you sign up with BlogExplosion, your site will eventually get approved, so you could start doing these things now and build up some credits. I don’t do auto-assign of credits. I go in and manually assign about 20 per day. That keeps a nice steady stream of visits to my site. It felt like it took a long time before my blog was approved in their system. The first time they gave me a message about non-english or non-us site, so I deleted it and reentered it. But eventually it was approved.

I am also building referrals. So far that is not working out for me. The referrals that you get would theoretically help you build your credits. The problem is getting the referrals to surf for traffic.

How do you use BlogExplosion?

Link Contest Results

Prize Unique Referred Traffic:
Prize Quantity of Links:
Prize Highest Google PR: Tie Between and, so the winner is determined by the most unique referred traffic so the winner is

Congradulations to C.McComsey of, B.Sanders of, and to all others who participated. Way to get off your duff and help a dude out. Thanks again!!

If you would like to see more detailed information I have provided the data that the winners were determined by. This pdf is a snapshot of the google analytics report of referring traffic for the contest period. Here is a csv file that contains all of the links as far as yahoo has indexed. The highest PR link, I had to manually go through all the registered links.