module development
How to create autocomplete form field in drupal
1. Create a form
print drupal_get_form('admin_add_users');
function admin_add_users(&$form_state, $pid) {
$form['admins_names'] = array(
'#type' => 'textfield',
'#title' => t('Conversation Admins'),
'#autocomplete_path' => 'itechmentors/autocomplete/multiple',
'#description' => t('Enter multiple names as comma separated values Like name1, name2, name3'),
'#default_value' => isset($def['admins_names']) ? implode(",", unserialize($def['admins_names'])) : NULL,
'#required' => FALSE,
);
$form['submit'] = array(
'#type' => 'submit',
Make Your PHP Variables Available to JavaScript
For my Visitor Info module I needed to pull some info out of the database and make that info available to JavaScript. Following is the code I used to do just that.
Add JavaScript From a Module
The following bit of code will add your javascript file to the page.
// get the path to the module
$mod_path = drupal_get_path('module', 'YOUR_MODULES_NAME');
// add the functions.js file where all the javascript will be located
drupal_add_js($mod_path .'/functions.js');Include the required Google file for mapping
Using Drupal's watchdog()
$ip = '192.168.1.1';
$msg = 'Requesting IP is %ip.';
$vars = array( '%ip' => $ip );
watchdog('citystate', $msg, $vars, WATCHDOG_INFO);$msg is what is printed to watchdog.
$vars is an array of stuff to be put into $msg.
Here 'citystate' is the module's name.