On occasion, you’re going to have some mammoth form that doesn’t validate properly with any Javascript validation library.   One event is when the form you are given to deploy has a lot of checkboxes and one of those checkboxes needs to be checked to be valid.  The easiest way to make sure this happens is to create a form submission even listener then if there’s at least one checkbox checked, it returns true at which time it triggers the form validation OR it sends the “e.preventDefault()” command, which will stop any further processes, in this case, triggering the form submission which would then trigger the validation.  It’s kind of pre-submit validation, but to me, it’s the fastest way to “piggyback” on the existing form validation if everything else works properly.

Here is a sample, and this is the form library that I think is incredibly reliable, clean, and very easy to use:

http://jqueryvalidation.org/documentation/

$("#mainForm").on('submit',function(e){

   if ( $("input[type='checkbox']:checked").length > 0) {


   }
   else {
         e.preventDefault();

         alert("Please check at least one category you wish to be listed in.");
         return false;
   }

   return true;

});


$("#mainForm").validate();

This works well CDN’d with Symfony form projects.


Log in to your server as root.  At the server’s command line, type “visudo”.

Scroll down file and add any usernames you want sudo access:
“new_user    ALL=(ALL) ALL”

Find out more about “sudo” here.


BitBucket is awesome, for unlimited free private repositories, you just can’t go wrong.  In two minutes you can get your website code for any project safely to their repositories, accessible from any where.  Of course, it has its limitations.  Take one instance where last week I committed revisions to ProflicFutility.com, a media-heavy website that sells stock video, images, etc, among other business media and services.  I accidentally forgot to exclude the media, so all these .mp4, video files, and stock photos were uploaded to the repository and exceeded the 2 GB limit for free repos.  On top of that, I also committed a bunch of useless files and folders from the Symfony cache, too.

This is where I usually have a ready-to-go .gitignore file in place in the web root to make sure that doesn’t happen, but I didn’t copy my template .gitignore file in there so I started getting “repository exceeded storage limits” notifications from BitBucket.

Also, in your .gitignore you can get the latest documentation from its built in help function on the command line:  “git help gitignore“.

The best way I found to exclude all files of a certain type is to create a .gitignore file in your web root and use wildcards.

So, to ignore all *.log files in any subfolder, use:

*.log

To ignore all files in a specific subfolder, use the “/**/" path wildcard after the sub folder.  So, perhaps in Symfony you don’t want anything in your app/ cache folders committed to your repo, you’d use:

 /app/*/cache/**/

Remember the paths in .gitignore are all relative to that .gitignore file!


To conform a datetime field to just a date in your results and make it easy to group TIMESTAMP fields in the format “2015-12-25 12:23:23” so you can group any datetime value into actual days for daily reports, use “DATE_FORMAT” below:

DATE_FORMAT(datetime_field, '%Y-%m-%d')

In other words, if you have values from a SELECT statement that are date AND time stamps and you want to group all those values into the DAY, DATE_FORMAT converts the value for you.

So, with these values in the field “created_at”:

2015-03-01 11:11:11
2015-03-01 16:13:132015-03-01 19:01:01
2015-03-03 11:19:23

The following MySQL SELECT statement

SELECT DATE_FORMAT(created_at,'%Y-%m-%d') as created_at_days FROM your_table GROUP BY created_at_days

Will result in the following results:
2015-03-01
2015-03-03


The Symfony documentation is getting better, but it still lacks more detail, which is why I’ve been collecting helpful tips and snippets here.  According to the Symfony docs, by default, the “redirectToRoute()" method performs a 302 (temporary) redirect, so in order to specify a 301 (permanent) redirect, you can add the third argument in this method within your controller and logic that would trigger a redirect.

public function indexAction()
{
    return $this->redirectToRoute('http://www.belchamber.us/page-to-redirect', array(), 301);  // 301 is where you can also specify 302
}