• About me
  • Php design patterns

dineshshrivastava

dineshshrivastava

Author Archives: dineshbhopal

CheckMySQL Engine of databse table

17 Monday Dec 2018

Posted by dineshbhopal in MySQL

≈ Leave a comment

For specific table:

SHOW TABLE STATUS WHERE Name = 'table_name';

For all tables of specific database:

SELECT TABLE_NAME,
ENGINE
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'database_name';

Or you can use this simple command, this will list all tables:

SHOW TABLE STATUS;

Advertisements

get file download link in drupal

24 Tuesday Jul 2018

Posted by dineshbhopal in Uncategorized

≈ Leave a comment

//set fid to your file’s fid.
//we can get fid from file_managed table
$fid = 1;

//build a link to the file by loading the file object and generating from the uri.
$file_download_link = file_create_url( file_load( $fid )->uri );

How to remove N/A from radio button options in drupal7?

26 Tuesday Jun 2018

Posted by dineshbhopal in Uncategorized

≈ Leave a comment

How to remove N/A from radio button options in drupal7?

If you dont want to show the N/A option in the radio buttons option lists, than make that field mandatory.
When you make that field required it will remove the N/A option.

But if you dont want to make that field required and also dont want to show N/A option, then you use theme hook function
theme_form_element($variables) to alter that.

function mytheme_form_element($variables) {
$element = $variables['element'];
// Disable radio button N/A
if ($element['#type'] == 'radio' && $element['#return_value'] === '_none') {
$variables['element']['#attributes']['disabled'] = TRUE;
}
return theme_form_element($variables);
}

you can use your theme’s name in place of mytheme in function name, and add this function to your theme’s template.php file.

Hide using CSS:

.form-radios .form-disabled {
display: none;
}

OOP Introduction

22 Friday Jun 2018

Posted by dineshbhopal in Uncategorized

≈ Leave a comment

Hello friends,

I am here to teach you Object oriented principles in very simple way.

Previously we were using functions only for more complex programs not object oriented method, and it worked, than why wee need to use OOP??

Because it contain variable and functions together in one unit, and its called object. and whole object oriented programming based on this object.

and containg the variable data and functions in one unit called the Encapculation.

for coding forget all length definations and keep these short terms in mind:

Class: a collection of vaiables and methods
Object: a thing or name
Instantiate: crating an object
Method: function of class
Property: variable of class

Set values in multiple select list using javascript and jQuery

16 Wednesday May 2018

Posted by dineshbhopal in Uncategorized

≈ Leave a comment

We can make multiple option selected in our HTML form using JavaScript and jQuery.

In Javascript:

document.getElementById('elementId').value = ["optionVal1", "optionVal2", "optionVal3"];

and in Jquery Its pretty:

$("#elementId").val(["optionVal1", "optionVal2", "optionVal3"]);

How to add HTML in drupal form

11 Friday May 2018

Posted by dineshbhopal in Uncategorized

≈ Leave a comment

If you want to add HTML in Drupal form using form api. you need to use #markup in that form field.

See the below example of form field:


 $form['form_field'] = array(
 
  '#markup' => 'HTML code here', // and add HTML in #markup. 
 
);

get drupal taxonomy term list using vocabulary

25 Wednesday Apr 2018

Posted by dineshbhopal in Uncategorized

≈ Leave a comment

Get drupal 7 taxonomy term list using vocabulary machine name

function get_taxonomy_terms_by_vocabulary($vocabulary_machine_name){

$term_data = array();
$vid = taxonomy_vocabulary_machine_name_load($vocabulary_machine_name)->vid;
$terms = taxonomy_get_tree($vid);

//If you want to get more custom fields value, than use
//$terms = entity_load('taxonomy_term', FALSE, array('vid' => $vid));

foreach($terms as $term){
$term_data[$term->tid] = $term->name;
}

return $term_data;
}

Drupal role, module & permission

05 Friday Jan 2018

Posted by dineshbhopal in Drupal 7

≈ Leave a comment

SELECT r.name,p.module,p.permission FROM role_permission p

left join role r on p.rid=r.rid

order by name,module, permission

Submit drupal form & node_save using hook_submit_form in Drupal 7

21 Monday Nov 2016

Posted by dineshbhopal in Drupal 7

≈ Leave a comment

function user_identity_form_submit($form, &$form_state) {
  global $user;
  global $base_url;
  //variable_set('identity_image', $form_state['values']['identity_image']);
  $file = file_load($form_state['values']['identity_image']);
  if($file){
    $file->status = FILE_STATUS_PERMANENT;
    file_save($file);
    file_usage_add($file, 'user_identity', 'user_identity', $file->uid);

    //create node identity
    $node = new stdClass();
    $node->type = 'user_identity';
    node_object_prepare($node);
    $node->title = 'Identity: '.$user->name;
    $node->field_photo_document['und'][] = (array)$file;
    $node->language = LANGUAGE_NONE;
    $node->uid = $user->uid;
    $node->status = 0;
    node_save($node);
...

Display image after upload using managed_file in Drupal 7

21 Monday Nov 2016

Posted by dineshbhopal in Drupal 7

≈ Leave a comment

function MODULE_NAME_theme() {
    return array(
      'MODULE_NAME_image' => array(
        'render element' => 'form',
      ),
    );
}

function theme_MODULE_NAME_image($variables) {
    $form = $variables['form'];
    if(isset($form['#file']->uri))
        $form['identity_image']['#markup'] = theme('image_style', array('style_name' => 'thumbnail', 'path' => file_build_uri(file_uri_target($form['#file']->uri))));
    $output = drupal_render_children($form);
    return $output;
}

function MODULE_NAME_form($form, &$form_state) {
    $form = array();
        $form = array();
        $form['identity_image'] = array(
          '#title' => t('Upload photo document'),
          '#type' => 'managed_file',
          '#required' => true,
          '#upload_location' => 'public://identity/'.$order->uid.'/',
          '#upload_validators' => array(
            'file_validate_extensions' => array('jpg png jpeg'),
          ),
          '#theme' => 'MODULE_NAME_image',
        );
        $form['submit'] = array(
          '#type' => 'submit',
          '#value' => t('Approved'),
        );
return $form;
}
← Older posts

Recent Posts

  • CheckMySQL Engine of databse table
  • get file download link in drupal
  • How to remove N/A from radio button options in drupal7?
  • OOP Introduction
  • Set values in multiple select list using javascript and jQuery

Archives

  • December 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • January 2018
  • November 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • February 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012

Categories

  • Ajax
  • Blog Links
  • CodeIgniter
  • CSS
  • Drupal
  • Drupal 7
  • Drupal Links
  • Health
  • Joomla
  • jQuery
  • Laravel
  • Links
  • Magento
  • Music
  • MySQL
  • Oops
  • PHP
  • SocialEngine
  • ubuntu
  • Uncategorized
  • Wordpress
  • Wordpress links
  • Zend

Meta

  • Register
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.com
View Dinesh Shrivastava's profile on LinkedIn
Advertisements

Blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy