Wednesday, January 1, 2014

Drupal-7 Creating Module based on node form

Hi,

Many times, we required to create custom node and the same we need to display as form in front end. In this case, we can create custom module Quick and Easily as below.

For eg. We have "contactinfo" node type and it's having fields like..

- Name
- Phone Number
- Message

First we need to create : contactinfo.info file

name = contactinfo module
description = contactinfo test module
package = contactinfo modules
core = 7.x

; Information added by Drupal.org packaging script on 2014-06-07
version = "7.x-1.x-dev"
core = "7.x"
project = "sandip"
datestamp = "1402151651"

Second We need to create : contactinfo.module file

/**
 * @file
 * An example of calling defualt Node and Block via Module
 */

/**
 * Implements hook_field_info().
 *
 * Provides the description of the field.
 */
function contactinfo_info() {
  return array(
    // We name our field as the associative name of the array.
    'contactinfo_basic_action' => array(
      'label' => t('Simple contact form creation'),
    ),
  );
}

function contactinfo_menu(){

    // Will be only used while we are dealing with ready made node form
    $items['contactinfo/test'] = array(
    'title' => t('Contact Info Form'),
    'page callback' => 'node_form_contactinfo',
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM,
    'file path' => drupal_get_path('module', 'node'),
    'file' => 'node.pages.inc',
  );
  return $items;
 
}

/*
 * Creating Sample Block
 */
function contactinfo_block_info(){
 
  $blocks['contactinfo_block'] = array(
    'info' => t('Create contactinfo block'),
    'status' => TRUE,
    'region' => 'sidebar_first',
    'visibility' => BLOCK_VISIBILITY_NOTLISTED,
  );
  return $blocks;
}

/*
 * Creating Sample Block view for contact info form
 */
function contactinfo_block_view($delta = '') {
  //  echo $delta;
  switch ($delta) {
    case 'contactinfo_block':
      module_load_include('inc', 'node', 'node.pages');
      $block['subject'] = t('Quick Contact');
      $block['content'] = node_form_contactinfo();
      break;
  }
  return $block;
}

/*
 * Function will display node on page as well as block
 */
function node_form_contactinfo(){

    //$nval = node_load(5);
    global $user;
    //echo $user->uid;
    $type = 'contactinfo';
    $form_id = $type . '_node_form';
    $node = new stdClass();
    $node->uid = $user->uid;
    $node->type = $type;
    node_object_prepare($node);
    $output = drupal_get_form($form_id, $node);
    return render($output);
}

/*
 * Default node form alter hook
 * You can add form CSS/Label as per your need.
 */
function contactinfo_form_contactinfo_node_form_alter(&$form, &$form_state, $form_id) {
    /* $form['field_phone'] = array(
    '#type' => 'textfield',
    '#title' => t('Phone Number/Mobile'),
    '#required' => false,
      );
   */
}

?>

                      ========= SAME CODE USING FORM API ============

/**
 * @file
 * An example of calling default Node and Block via Module
 */

/**
 * Implements hook_field_info().
 *
 * Provides the description of the field.
 */
function contactinfocustom_info() {
  return array(
    // We name our field as the associative name of the array.
    'contactinfocustom_basic_action' => array(
      'label' => t('Simple contact form creation'),
    ),
  );
}

function contactinfocustom_menu(){
 
     $items = array();  
    // Will be only used while we are dealing with ready made node form
    $items['contactinfocustom/test'] = array(
    'title' => t('Contact Info Custom Form '),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('contactinfocustom_getform'),  
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM
  );
  return $items;
 
}

/*
 * custom form creation
 */

function contactinfocustom_getform($form, &$form_state){
 
    $form = array();
 
    $form['title'] = array(
        "#title" => t('Name'),
        "#type" => t('textfield'),
        '#size' => 20,
        '#maxlength' => 20,
        "#required" => TRUE,
    );
 
    $form['field_phone'] = array(
    '#type' => 'textfield',
    '#title' => t('Phone Number/Mobile'),
          '#size' => 20,
        '#maxlength' => 10,
    '#required' => false,
      );
 
    $form['body'] = array(
    '#type' => 'textarea',
    '#title' => t('Information About You'),
    '#required' => false,
      );
 
     $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit')
      );
    return $form;
 
}

function contactinfocustom_getform_validate($form, &$form_state){
 
    $values = $form_state['values'];
    if($values['title'] == ''){
         form_set_error('title', t('Set Any Error MSG'));
    }
 
}

function contactinfocustom_getform_submit($form, &$form_state){
 
    global $user;
    $values = $form_state['values'];
    $node = new stdClass();
    $node->type = "contactinfo";
    node_object_prepare($node);
 
    $node->title = $values['title'];
    $node->uid = $user->uid;
    $node->status = 1;
    $node->promote = 0;
    $node->language = LANGUAGE_NONE;
 
    $node->field_phone[$node->language][] = array('value' =>$values['field_phone'] ,);
    $node->body[$node->language][] = array('value' =>$values['body'] ,);
      if($node = node_submit($node)){
          node_save($node);
          drupal_set_message(t('Contact detail form data has been saved successfully.'));
       
       /* $params['puser']['subject'] = t('New Contact entry Found!!!');
        $params['puser']['message'] = t('Please check the admin panel for contact entry!!!');
     
$params['padmin']['subject'] = t('Thank you for submission!!!');
$params['padmin']['message'] = t('Thanks for contacting us');
$site_admin = variable_get('site_mail', '');

drupal_mail('personal_frm', 'puser', $values['email'], 'EN', $params);
drupal_mail('personal_frm', 'auser', $site_admin, 'EN', $params);
         */
      }
 
 
}

?>







Friday, September 10, 2010

How to make quick site in Joomla?

Hello Friends,


Based on my past experience with Joomla programming, I want share with you information about quick creating Joomla site.

What basic you should know?

If you want to make quick Joomla site then you must know about the install process of modules which is ready made available in Joomla.

Installation process is also very simple. Just need to download stable version from Joomla.org site.

Follow the guide line and  given document which is wizard base only next to next button process.

This process will create quick default Joomla site with default theme options.

Now what to do?

Suppose if your requirement is as below

1. Site should be looking Good (Need a Good Theme)
2. Dynamic content management which is already available at back-end (With easy to use editor..its called article management)
3. Contact us page which is ready made module in default Joomla installation.
4. Photo Gallery which is ready made module available in Joomla.org and easy to use.
5. Polling system which is now a day’s very popular.



If you have above simple requirement then you can complete site within ONE DAY. so follow below process.

1. Google is great guru. So try to find out the free "Joomla Themes". You will see lots of themes  "paid and
    free". Mostly tried with free one b'coz paid will ask for money ...ooops :)

   Don't worry; I have solution, all things can be easy either this or other way. Below is link where you must   found free download links which is paid in other sites.

   URL: http://www.amaderforum.com/

   Above site having lots free template link which is really nice and attractive and also its using rapid share. So be careful for the same.(Means one day only one thing download with some limited size).

   So if you get the free theme,  Just install it form back-end admin panel and it done.

2. If you get good theme then your 60 to 70% work over now. Just from back-end add your contents in related links it’s also easy..Right?

3. Contact Us: which is also readymade module you only need to link up it.

4. If you want nice photo gallery then lot free extension available at Joomla.org. But my preference is "POCHA Gallery” which is widely used on Joomla site and has lots of options to represent it. So Quick install it and upload your nice photos and things are over. Great..We are near to finish.

5. If you are popular in group then you can also use polling system for more popularity which is ready made module available in default Joomla setup and it’s easy to use... :)

So with nice theme your basic site is ready now. It will be better if you know what you want to do...

Okay...Guys...Why are you waiting just checked out, make nice site and need any help then i am always ready...just post your needs... :)

Cheers,
Sandip (Web Developer)

Saturday, March 27, 2010

Why Joomla's component not having the same MVC structure like joomla 1.5?

Hello Friends,

    I am working in joomla since 1 year and i have also worked on many components but when i got the new project with new component , every time i face the issue with standard coding format. Like joomla 1.5 having the MVC structure but the popular component which is paid one, but still not using the MVC structure.

There lots of component which very powerful and its using in many sites but still not having common MVC structure. so due to that joomla developer needs learn coding structure every time and facing the issue while learning the new component.

Advantage of the common structure : All have to learn the same flow and also having the fastest grow related to publish component. So please my suggestion is to when we follow the any structure like joomla then we should also have the strict standard format to create the new component, which beneficial to grow up whole joomla community.

Here is the list of component which is not follow joomla 1.5 standard:
1. Jomres (Very popular in hotel booking site)
2. Virtumart (Very popular in shopping cart implementation)

there are the other lots of component which is build with very poor standard and its not maintainable at the time of customization.

So if you are the joomla developer and the facing the issue with above points the please post your suggestion to improve the joomla's component standard.


Regards,
Sandip

Wednesday, March 17, 2010

2 Mins to place the Google map in Joomla

Hello All,

   I am working in joomla since last one year and sometimes, i really felt big the issue with google map because I have not found such good plugin OR Module which is display the map as many way as possible. So recently in joomla's plugin directory i have found such useful plugin which is working great with article and contact us page.



Mostly, we need the Google Map in (Contact us and Article pages) and this plugin is display the map in such a nice way with one line code.

Google Map display in article page:

Below is the syntax for the same

{mosmap lat='32.7659074'|lon='-117.2254277'|zoom='18'|rotation='1'|mapType='Hybrid'}

By changing the map type you can get multiple types of map views.

Google Map display in contact us page: This is little bit tricky but its work nice. you should need to change in main index.php file. Below is the code you need to put in index.php file



Add these lines at line 84 after $mainframe->render();:
JPluginHelper::importPlugin('content');
$tmp_row->text = JResponse::getBody();
$tmp_params = new JParameter(null);
$mainframe->triggerEvent('onMap', array( &$tmp_row, &$tmp_params ), true );
JResponse::setBody($tmp_row->text);

* So above code will work in contact us page. for more details please follow below link.
How to put Google Map Inside the Contact us page



* For downloading the plugin please follow below link.


Plugin download link

I have also done many R & D with this Plug-in. So please let me know if you have any issue with this plug-in. I will try my best to solve out it.

Regards,
Sandip

Sunday, February 21, 2010

JavaScript Date and Time Functions

Hi All,

   For the getting real time date time function solutions please visit below links.

1. JavaScript Date and Time Functions from Quackit.com
2. JavaScript Date and Time Functions from Bluesmoon.info
3. JavaScript Date and Time Functions from Blog.stevenlevithan.com

Saturday, February 13, 2010

Google Website Optimizer Plugin (Joomla! 1.5)

Hello All,

         Found great plug-in for the Joomla developers. Using this you can increasing your website traffic and optimize the code. So dont for getting more rewards use this plug-in as well as advice your clients to get more business.

Plugin Link:

Google Website Optimizer Plugin


For getting more info refer the Joomla org.

Direct path to Plugin

Dont miss above while working with great web-site of joomla.

Regards
Sandip Chhaya

Thursday, February 4, 2010

New EIOFAX.EXE - Threat report!

Hello All,

I have currently, faced with very strange virus definition. This virus is recently identified in this year 2010.

Behavior of virus:

This will load in registry of windows and automatically create its "EIOFAX.EXE" file in windows and load in place of "explorer.exe". Now, due to non-availability of "explorer.exe" windows will not show your desktop(no right click, no taskbar etc.) only will show window its own create "explorer". This virus will only increasing the disk space and create the big issue after few days.

Solution: From one of the blog I have found the solution like we need clean up that particular files from "REGEDIT". so it will not create that "EIOFAX.EXE".

Few Related Links:

1. EIOFAX.EXE Solution Link1
2. EIOFAX.EXE Solution Link2

Please let me know if anyone know better solution to remove about virus Threat.

Best Regards,
Sandip