Archive for category CMS

SOLVED!! How can you make form_set_error() affect the only form submitted?

Drupal form_set_error() function provide validation message based field name. So if you have same field name in same page , after the submission you can see both fields are marked as red color(Error class). It validate or show message for right form but it provide error class for all element which are same.

I found a way to solve it. If you render those form using drupal_get_form then you can add one extra line in top to get rid of this problem.

for example :-

drupal_static_reset('form_set_error'); // adding this line makes you life out of hell.-)
$form = drupal_get_form('webform_client_form', $node, $submission);
return drupal_render($form);

Ref:- http://drupal.stackexchange.com/questions/29113/how-do-i-make-form-set-error-affect-the-submitted-form-only
Advertisements

,

Leave a comment

Creating custom filters with drupal and views

If you want to know how to create custom filters with Drupal and view please follow the step from the link

http://www.chadcf.com/blog/creating-custom-filters-drupal-and-views

But you need to remember some missing information :-

it is done in views api 2 , so function definition you need to change. for example

$this->query->add_where($this->options[‘group’], “term_node.tid = %d”, $value); should be

$this->query->add_where($this->options[‘group’], “term_node.tid”, $value,’=’);

ofcourse remember to add those files inside module.info file, otherwise you will see broken handlers in your view.

Leave a comment

Call to undefined function entity_revision_is_default() on line 306 of field_collection.module

When i updated field collection module to beta7 to get support of version control , I start getting this error. It because of entity api module version.

Updated entity api module to 1.0 version solve the issue right away.

 

ref : https://drupal.org/node/1883924

Leave a comment

Floating a textfield next to a radio button in Drupal form

This can actually be done entirely with the Forms API. Here is an example:

 

// This will mimic the normal form element title as well as provide the group for our radio options.
$form[‘nations’] = array(
‘#type’ => ‘item’,
‘#title’ => t(‘Nationality’),
‘#description’ => t(‘<Enter your field description here.>’)
);
$form[‘nations’][‘american’] = array(
‘#type’ => ‘radio’,
‘#title’ => t(‘American’),
‘#default_value’ => 1,                    // If there is a default value, this should also be specified for each radio button.
‘#return_value’ => 1,
‘#parents’ => array(‘nations’),           // You must specify this for each radio button for them to act as a group.
‘#prefix’ => ‘<div>’  // The first radio button needs to make the style match a normal radios group.
);
$form[‘nations’][‘german’] = array(
‘#type’ => ‘radio’,
‘#title’ => t(‘German’),
‘#return_value’ => 2,
‘#default_value’ => 1,
‘#parents’ => array(‘nations’)
);
$form[‘nations’][‘other’] = array(
// The ‘container-inline’ class places elements next to each other, while the ‘form-item’ class provides the correct spacing between options.
‘#prefix’ => ‘<div>’,
‘#suffix’ => ‘</div>’
);
// By supplying the title here, instead of using the ‘#field_prefix’ property of the textfield, clicking the text will also select the radio button.
$form[‘nations’][‘other’][‘other_option’] = array(
‘#type’ => ‘radio’,
‘#title’ => t(‘Other:’),
‘#return_value’ => 3,
‘#default_value’ => 1,
‘#parents’ => array(‘nations’)
);
$form[‘nations’][‘other’][‘other_textfield’] = array(
‘#type’ => ‘textfield’,
‘#default_value’ => ”,
‘#size’ => 20,         // The default size is a bit large…
‘#suffix’ => ‘</div>’  // End of the “form-radios” style.
);

In your validation and/or submit callbacks, the selected radio option will then be in $form_state['values']['nations'] and the textfield value will be in $form_state['values']['other_textfield'].

With a little more work, you can change the example so that you don’t have to create each element manually .-)

, ,

Leave a comment

How to disable views programmatically when the offering module is disabled

Here is a snippet of code you would put in mymodule.install

/**
* Disable workbench views
*/
function mymodule_update_7001() {
// a list of views (their view name) I want to disable
$viewnames = array(
‘workbench_current_user’,
‘workbench_edited’,
);
// grab list of views that are already disabled
$views_status = variable_get(‘views_defaults’, array());
// add our views to be disabled to the list
foreach ($viewnames as $key => $viewname) {
$views_status[$viewname] = TRUE;
}
// reset the variable with the new list
variable_set(‘views_defaults’, $views_status);
// empty cache now
if (function_exists(‘views_invalidate_cache’)) {
views_invalidate_cache();
}
}

Leave a comment

How To Disable Custom Panel Page Programmatically?

You can automatically disabled custom panel page  via hook_update_N.  After little digging around in CTools module codebase, I ended up with the following code snippet.

$page = page_manager_get_page_cache('<page_name>'); // Replace <page_name> 
$function = ctools_plugin_get_function($page->subtask, 'enable callback');
$result = $function($page, TRUE);
menu_rebuild();

6 Comments

Create Custom Search Criteria Page in Drupal7

function my_module_menu(){
$items = array();

$items[‘my_search_page’] = array(
‘title’ => t(‘my search screen’),
‘description’ => ‘when the present views filter can not suit your need such as dependent dropdown’,
‘page callback’ => ‘drupal_get_form’,
‘page arguments’ => array(‘my_search_page’),
‘access callback’ => TRUE,
‘type’ => MENU_CALLBACK,
‘access arguments’ => array(‘access content’)
);

return $items;
}

function my_search_page($form, &$form_state) {

if (!isset($form_state[‘storage’][‘my_module’][‘search_criteria’])) {
return drupal_get_form(‘my_search_form’);
}

$build = array();
$rows = array();

$header = array(
array(‘data’ => ‘Title’, ‘field’ => ‘title’, ‘sort’ => ‘asc’),
array(‘data’ => ‘Node ID’, ‘field’ => ‘nid’),
array(‘data’ => ‘Type’, ‘field’ => ‘type’),
array(‘data’ => ‘Created’, ‘field’ => ‘created’),
array(‘data’ => ‘Published’),
);

$title = $form_state[‘input’][‘title’];

$query = db_select(‘node’, ‘n’)
->condition(‘status’, 1) //Only published nodes, change condition as it suits you
->condition(‘title’, $title.’%’, ‘LIKE’)
->extend(‘PagerDefault’) //Pager Extender
->limit(10) //10 results per page
->extend(‘TableSort’) //Sorting Extender
->orderByHeader($header) //Field to sort on is picked from $header
->fields (‘n’, array (
‘nid’,
‘title’,
‘type’,
‘created’,
‘status’,
));

$results = $query->execute();

foreach ($results as $node) {
$rows[] = array(
l($node->title, ‘node/’. $node->nid),
$node->nid,
$node->type,
format_date($node->created),
$node->status
);
}

//Theme the html table: http://api.drupal.org/api/drupal/includes–theme.inc/function/theme_table/7
$content = theme(‘table’,
array(
‘header’ => $header,
‘rows’ => $rows,
‘sticky’ => TRUE, //Optional to indicate whether the table headers should be sticky
’empty’ => ‘Find not found..’, //Optional empty text for the table if resultset is empty
)
);

$build[‘content’] = array(
‘dummy1’ => my_search_form($form, $form_state),
‘dummy2’ => array(‘#markup’ => $content,),
);

$build[‘pager’] = array(
‘#theme’ => ‘pager’,
‘#weight’ => 5,
);

return $build;
}

function my_search_form($form, &$form_state) {

$form[‘criteria’] = array(
‘#type’ => ‘fieldset’,
‘#title’ => ‘Search Criteria’,
‘#attributes’ => array(‘class’ => array(‘container-inline’)),
);

$form[‘criteria’][‘title’] = array(
‘#type’ => ‘textfield’,
‘#title’ => t(‘title’),
‘#value’ => (isset($form_state[‘input’][‘title’])) ? $form_state[‘input’][‘title’] : “”,
‘#size’ => 10,
‘#maxlength’ => 20,
);

$form[‘criteria’][‘submit’] = array(
‘#type’ => ‘submit’,
‘#value’ => ‘search’,
‘#submit’ => array(‘my_search_form_submit’),
);

return $form;
}

function my_search_form_submit($form, &$form_state) {
$form_state[‘storage’][‘my_module’][‘search_criteria’] = $form_state[‘values’];
$form_state[‘rebuild’] = TRUE;
}

Ref : http://siripong-computer-tips.blogspot.se/2011/12/custom-search-criteria-page-drupal7.html

,

Leave a comment

Hook function for email_registration drupal module

Some of the site needs email as sername for their Drupal site. Email Registration module helps to get rid of that problem.
but  it saves username from the email address whatever that is before @.

example : takim.islam@googol.se  save username as : takim.islam

Many people might think , they can update their username from hook_user case ‘Insert’ , but it will not work.
They actually dont need to do anything such that. Because there is already a hook function hook_email_registration_name($edit, $account)
which people can implement from their own module like :

mymodule_email_registration_name($edit, $account)
{

$string = ‘Takim Islam’; // or replace with any value from $account / $edit

return $string;

}

Thats it, your problem is solved!

 

Leave a comment

Multiblock Module

Drupal’s block module is limited by the fact that a block can only have one instance. Each block has a 1:1 relationship with its region, weight, visibility (and other) settings. This means that it is impossible to have blocks in multiple regions or to have blocks that have different settings on different pages.  MultiBlock module solves this problem by allowing you to create multiple Block Instances of already existing blocks.

http://drupal.org/project/multiblock

Leave a comment

Detect frontpage in Drupal module

You can detect whether the current page is frontpage or not by

drupal_is_front_page ()

http://api.drupal.org/api/drupal/includes–path.inc/function/drupal_is_front_page/6

Leave a comment