Posts

Showing posts from February, 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'), );

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);

Syntax Highlighting with Blogger Engine

I was trying to style the code snippets highlighted as code as developer in my blog. Did it using some custom css but no positive impression. Recently googling, found an article abt that here . This can be done using syntaxhiglighter . Drop this code right before your </head> tag... and save. And here is the way how you can use it. 1. Using <script> tag with CDATA This will output.... // Commenting this function function custom_one($var) { if($one == $two) { $three = array( 'one', 'two' ); } } 2. Using the <pre> tag. // Commenting this function function custom_one($var) { if($one == $two) { $three = array( 'one', 'two' ); } } This will output.... // Commenting this function function custom_one($var) { if($one == $two) { $three = array( 'one', 'two' ); } }

Webform in Blocks - Drupal 7

Image
In Drupal 6, we have been using FormBlock to show the form in the block. But in D7 its pretty simple to do so. After creating a webform, goto form setting at 'node/103/webform/configure' Move down to Advaced Setting and check the "Available as block" option.