Monday, April 11, 2016

Display error message on Ajax form submit Drupal 7

Display error message on Ajax form submit Drupal 7

To Display error message after ajax form submit you need to take care the following points.

 $form['submit_button'] = array(  
     '#type' => 'submit',  
     '#value' => t('Save'),  
     '#ajax' => array(  
       'callback' =>'form_ajax_callback'  
       'wrapper' => form-html-id-name ,  
       'event' => 'click',  

In the wrapper you should take the form-id.
For example if your form name is abc_form then generated html form id will be abc-from. Otherwise errors will not get displayed.

Add same form multiple times on page Drupal 7

Show same form multiple times on page

To display custom form multiple times on same page you need to use hook_forms . Below example

  $form = drupal_get_form("workflow_tab_form_$node->nid", $node, $workflow->wid, $states, $current);  
  * Implements hook_forms().  
  * Allows the workflow tab form to be repeated multiple times on a page.  
  * See  
 function workflow_forms($form_id, $args) {  
  $forms = array();  
  if (substr($form_id, 0, 18) == 'workflow_tab_form_') {  
   $forms[$form_id] = array('callback' => 'workflow_tab_form');  
  return $forms;  

Or you can refer 

Tuesday, January 19, 2016

Drupal 8: How to create user with role programatically

Drupal 8: How to create user with role programatically

$values = array(
'field_first_name' => 'test',
'fieldt_last_name' => 'g',
'name' => 'test123',
'mail' => '',
'roles' => array('administrator'),
'pass' => 'password',
'status' => 1,
$account = entity_create('user', $values);

Monday, January 4, 2016

MySQL 5.7.7 - Access denied

You get the 'Access denied' message while login into mysql server after successful installation of MySQL 5.7.X on Centos 7/RHEL. 

Here is the solution.

Note: before trying following instruction please do not start mysql service otherwise steps will not work.

  • MySQL 5.7.X or higher generates a temporary random password.
  • Fire the blow command from console or refer URL
  • shell> bin/mysqld --initialize --user=mysql
  • shell> bin/mysqld --initialize-insecure --user=mysql
  • Password is stored in mysql error log file, located at /var/log/mysqld.log
  • use below command to see the password:
  • shell > sudo grep 'temporary password' /var/log/mysqld.log
  • you will get password like '/vHb/aao-6sX'
  • Try to login with above output password.
  • And change password using below command
  • ALTER USER 'root'@'localhost' IDENTIFIED BY '#*Admin123456';
  • Query OK, 0 rows affected (0.01 sec)
  • Password strength should be good enough otherwise system will not accept it.
  • Now you can start mysql server using below command
  • shell > sudo systemctl start mysqld.service

Monday, December 14, 2015

Drupal 8: show all errors or enable debug mode

To show all errors on Drupal 8 page, do the following steps.

  • add below code into sites/default/settings.php
  •  $config['system.logging']['error_level'] = 'verbose';  
  • Clear cache from admin/config/development/performance
  • You are done!!!

Drupal 8: Uninstall or Disable module manually

Follow below steps in uninstall Broken module from Database

  • Find record 'core.extension' in `config` table.
  • Remove module name entry from serialize string which is stored in blob field like below example

  •  $data = unserialize('a:2:{s:6:"module";a:52:{s:14:"automated_cron";i:0;s:10:"basic_auth";i:0;s:5:"block";i:0;s:13:"block_content";i:0;s:10:"breakpoint";i:0;s:8:"ckeditor";i:0;s:5:"color";i:0;s:7:"comment";i:0;s:6:"config";i:0;s:7:"contact";i:0;s:10:"contextual";i:0;s:8:"datetime";i:0;s:5:"dblog";i:0;s:13:"my_module";i:0;s:13:"doctrine_base";i:0;s:18:"dynamic_page_cache";i:0;s:6:"editor";i:0;s:5:"field";i:0;s:16:"field_collection";i:0;s:8:"field_ui";i:0;s:4:"file";i:0;s:6:"filter";i:0;s:3:"hal";i:0;s:4:"help";i:0;s:7:"history";i:0;s:5:"image";i:0;s:4:"link";i:0;s:7:"menu_ui";i:0;s:4:"node";i:0;s:5:"oauth";i:0;s:7:"options";i:0;s:10:"page_cache";i:0;s:4:"path";i:0;s:4:"push";i:0;s:9:"quickedit";i:0;s:3:"rdf";i:0;s:4:"rest";i:0;s:6:"restui";i:0;s:6:"search";i:0;s:13:"serialization";i:0;s:8:"shortcut";i:0;s:6:"system";i:0;s:8:"taxonomy";i:0;s:4:"text";i:0;s:7:"toolbar";i:0;s:4:"tour";i:0;s:6:"update";i:0;s:4:"user";i:0;s:8:"views_ui";i:0;s:17:"menu_link_content";i:1;s:5:"views";i:10;s:8:"standard";i:1000;}s:5:"theme";a:4:{s:6:"stable";i:0;s:6:"classy";i:0;s:6:"bartik";i:0;s:5:"seven";i:0;}}');  
     echo (serialize($data));  

  • Save the table data again.
  • Follow the same step into `cache_config` table.
  • Remove php folder from sites/default/files/
  • You are done!!!

Tuesday, April 21, 2015

Zend Auth example with extra columun

  $request = $this->getRequest();  
       if ($request->isPost()) {  
         $params = $this->filterInput($request->getParams());  
         $db = Zend_Db_Table_Abstract::getDefaultAdapter();  
         $auth = Zend_Auth::getInstance();  
         $authAdapter = new Zend_Auth_Adapter_DbTable($db, 'mdl_registration_user');  
         // extra validation  
         $authAdapter->getDbSelect()->where('countrycode = +'.$params['country']);  
         $result = $auth->authenticate($authAdapter);  
         if ($result->isValid()) {  
           $user = $authAdapter->getResultRowObject();  
           $flash_obj->addMessage('You have loged-in successfully');  
         } else {  
           $this->view->messages = "Invalid username or password. Please try again.";  
           return ;