Thursday, August 14, 2014

Construct URL after submit.

When you create a custom form using some custom module, and you want to construct the url after user submit the form... use

 $form['method'] = 'get';

in the form generation code.

Thursday, March 27, 2014

Convert Putty ppk key to SSH key

You cant use a putty ppk to ssh to a remote server from you linux machine. In that case you may need to first convert ppk to ssh file.

For that first you need to install putty on your machine.

$ sudo apt-get install putty

Then goto the directory and run the  following command to convert ppk to ssh file.

$ puttygen key.ppk -O private-openssh -o key.ssh


Here, I assume, kep.ppk is you ppk file and key.ssh will be newly created ssh file.
After this you can ssh to your remote machine/server using following command.

$ ssh user@myserver.com -i key.ssh

Wednesday, March 12, 2014

Not Found - phpmyadmin

I installed phpmyadmin with apache on Linux but I was seeing this at localhost/phpmyadmin

    Not Found
    The requested URL /phpmyadmin/ was not found on this server.
    Apache/2.2.17 (Ubuntu) Server at localhost Port 80


To fix this I had to make changes to apache.conf

sudo vim /etc/apache2/apache2.conf

and added the following line at the end...

Include /etc/phpmyadmin/apache.conf

then restart the apache..

sudo service apache2 restart

 

Installing NetBeans - Linux

Before installing NetBeans you need to install JDK software.
You can install the JDK software and NetBeans IDE in directories of your choice. Note: This installer does not displace the system version of the Java platform that is supplied by the operating system.

You can run the following command to install JDK.

sudo apt-get install openjdk-7-jdk

Go to the NetBeans download page and download the PHP package. Save the file on the desktop.

Now open terminal and run the following command.

sudo sh netbeans-7.4-php-linux.sh

After unpacking, you will find with the first step of the installation wizard.
Go through the installation wizard.
After that you will find net beans at Dash home or Applications.

Now if you need to configure Netbeans for Drupal, see this.

Friday, February 28, 2014

Compare FIELD value befaore saving the form - Form API

If you want to compare a field value with it self it was changed or not, you can do it using $node->original in hook_node_presave
function custom_node_presave($node) {
 if ($node->field_name == 1 && $node->original->field_name == 0) {
  //Do the magic here...
 }
}

Here I am comparing if checkbox was newly checked or was already checked. :)

Set value for CheckBox field - Form API

By default checkbox works with 1, 0 values to be checked, unchecked respectivly.

$form['custom_checkbox'] = array(
      '#type' => 'checkbox',
      '#title' => 'Title',
      '#default_value' => variable_get('custom_var'),
    );


you can use #return_value to set a desired value for the checkbox field is it is selected.

$form['custom_checkbox'] = array(
      '#type' => 'checkbox',
      '#title' => 'Title',
      '#return_value' => $key,
      '#default_value' => variable_get('custom_var'),
    );

Thursday, February 27, 2014

Ajax Status Message - Drupal

I was trying to show status message against an ajax call. Was using rules_link to promote nodes clicking on a link. And wanted to show message if it was done.

Here is how I did it....
$commands = array();
$commands[] = ajax_command_prepend('div#ajax-status-messages-wrapper', drupal_set_message(variable_get('limit_po_notification'), 'error'));
return array('#type' => 'ajax', '#commands' => $commands);