Drupal 7: hiding/showing form api elements when a checkbox is checked or not

I was trying to make a file type element appear/disappear when a checkbox was checked or not.
When i added the ‘#states’ declaration in ‘myfile’ element it didn’t work as expected!
I had to add the ‘myfile’ element in a ‘container’ type element and add to that the ‘#states’ declaration.

  $form['want_to_upload'] = array(
        '#type' => 'checkbox',
        '#title' => t('Yes i want to upload a file'),

  $form['upload_container'] = array(
        '#type' => 'container',
        '#states' => array(
            "visible" => array(
                "input[name='want_to_upload']" => array("checked" => TRUE)),

  $form['upload_container']['myfile'] = array(
        '#type' => 'file',
        '#title' => t('Choose your file'),
        '#description' => t('You are allow to upload jpg, jpeg, png, gif and pdf, 5MB Max Size'),

Laravel 5 – Form Validation of array of input elements

I have been using Laravel latelly. A problem that i had to overcome was using the validation mechanism of Laravel
for validating a variable number of form elements.

I made a dynamic form that someone could add many email input elements with name=’email[]’

The solution to validate each and everyone of these elements was not obvious and after some searching in the framework
the following code in the controller worked:

        $validator = Validator::make($request->all(), [
            'email' => 'array' //i declare the email as an array of elements

        $validator->each('email', ['email']); //Here i declare the rules that will be executed for each elements in the array

        if ($validator->fails()) {
            return redirect('mycontroller/edit/'.$id)


MySQL INSERT INTO ON DUPLICATE KEY UPDATE , regarding update triggers

This is to share some insight on the subject of mysql triggers in connection with INSERT INTO ON DUPLICATE KEY UPDATE statement.

When you execute an SQL UPDATE query, the update triggers are fired regardless of whether you changed a value or not in a specific row.

UPDATE myTable SET myColumn='test' WHERE id=100;

The above query will fire the update trigger (before or after) even if ‘myColumn’ already has the value ‘test’ for row with id=100

This is not the case with INSERT INTO ON DUPLICATE KEY UPDATE query.


INSERT INTO myTable (`id`, `myColumn`) VALUES (100, 'test') ON DUPLICATE KEY UPDATE myColumn='test';

The above query will not fire any UPDATE trigger if there is already a row with id=100 and ‘myColumn’ already has value ‘test’ !!!


IE11 and expression evaluation regarding Boolean

It seems that a lot of stuff changes with IE11. Some legacy code stopped working out the blue.
After some debugging it seems that some expressions that have been evaluating to true, now are being evaluated to false.


if(document.ActiveXObject) //document.ActiveXObject is a valid function in IE 11
    alert("YES!!!");  //this never gets called in IE 11

Boolean(document.ActiveXObject) gets evaluated to true in IE 10 but in IE 11 is evaluated to false, while it is still a valid function.

Whatever, just thought this might help someone.


Google Analytics for WordPress – multisite not sufficient permissions solution

It is one of those times that you relive all that has passed.

I came across my own solution i had shared with the community back then, more than 2 years ago.

Time flies and time mosquitoes.

The solution is you need to edit the file wp-content/plugins/google-analytics-for-wordpress/admin/yst_plugin_tools.php at line 16

and replace the line

var $accesslvl = 'edit_users';


var $accesslvl = 'activate_plugins';


jQuery UI selectable, how to programmatically select option

If you need to programmatically select an option, using events, so that your callbacks are called then you can do the following:
Suppose we have a ul element with id mySelectUlID, and i want to add an extra element to the end of it and also select it.

This is done like this:

    $('#mySelectUlID').append('<li class="ui-widget-content ui-selectee ui-selecting">another</li>');



The code is valid for the latest jQuery 1.10 and is self explaining i believe.


Jquery Tools library problem with modal overlay not appearing … a solution

So i was using the library of jquery tools recently and wanted to use the modal box with the nice overlay in the background.

I did all that was suggested yet the overlay didn’t appear. The solution was simple. I had downloaded a custom version of the jquery tools library and in an effort to save some bytes didn’t include a crucial part of the library named Expose.

The overlay is based on the ‘Expose’ part of the library. If you take a carefull look a the modal box documentation it is mentioned: ‘This feature can be achieved with the Expose tool which is tightly integrated with this overlay tool.

If you want a custom version of jquery tools, don’t forget to click on Expose.

That’s all for now.