nanodano's blog

Advertisement

Advertisement

AJAX Form Submit with CakePHP 2.x

CakePHP has some great tools for a PHP developer to crank out JavaScript functions using only PHP. The JsHelper supports Prototype/Scriptaculous, Mootools/Mootools-more, and jQuery/jQuery UI. Refer to the CakePHP Book for details on all the functions provided by the JsHelper. In this example we're going to look at a creating a contact form that submits via AJAX, but also works properly for users without JavaScript.

Writing Secure Code with CakePHP 2.x Forms

CakePHP is one of my favorite web frameworks. There is one glaring security hole that caught my attention though. Without proper care from the developer, users have the potential to tamper with data sent with forms. For example, a common operation is to take the value from a form and save it like this:

$this->User->save($this->request->data['User']);

Let's say the user manipulates the form and adds this line:

Responsive CSS Media Queries

Responsive design has been a big boom recently and it's still a mystery to some. Let's see just how easy it really is. Let's say you want to start simple with a normal desktop version of your website and one suitable for smaller screens like mobile phones. Let's start with something like the menu. You can create one menu and set it to display for large windows and make a compact menu, perhaps a dropdown, for smaller screens. This is where CSS Media Queries come in. In the HTML there can be two different menus created with only one set to display at a time.

Google Analytics Event Tracking in Drupal 7 (Hooks & OnClick)

Event tracking with Google Analytics has pretty much become a standard on all new sites. Google provides ample documentation on using the analytics, but the tricky part is getting it to integrate the way you want with Drupal. The Drupal Google Analytics module offers basic functionality out of the box. It can track page hits, specific user roles, offsite links, and download clicks. It also supports custom variables using tokens.

Chrome Extensions for Web Developers

There are many 'Top X useful extensions for web developer' posts out there. The problem I have with them is that they recommend multiple modules that do the same thing. For example, the 'web developer' and 'pendule' modules both offer a color picker tool, so I don't really see the need for another special extension just for color picking. Same with browser resizing, why would I want 3 extensions installed for that? Also, everyone should already have a method of taking screenshots (full or partial.) Even Windows comes with a basic snipping tool that does a perfect job.

16 Recommended Drupal Modules

These 16 recommended Drupal modules are not all recommended for every project, but they among the more useful modules out there. Many of them are useful only for site developers.

Admin Menu - An improved admin toolbar with drop down menus.

Backup Migrate - A must have for importing/exporting Drupal databases. Conveniently omits the data from the cache tables. Admins can schedule regular backups on a timed basis.

CakePHP vs Drupal

There are many PHP frameworks out there, but 2 of my personal favorites are Drupal and CakePHP. WordPress is another popular in the world, and I have done many projects with it. I will say that WordPress has great documentation and a clean API, but it is rather limited in its capabilties. CakePHP and Drupal have proven to be flexible, scalable, and perfect for certain uses. The bottom line in this debate is that both are great, and both serve their purposes. Between CakePHP and Drupal, I feel a project of any size can be accomplished. 

Create Script from Bash History

The script program (bsdutils) will output the whole terminal output to a file. This can be helpful for logging and creating scripts out of history.

The approach here is to output the command history to a file and then manipulate the file a bit to get what we want.

history 3 > script.sh

This will output the last 3 commands to script.sh. Note that the actual history command will become the most recent event in history, and will be output in the file. This can be edited out manually or using this command:

Advertisement

Advertisement