conformation alert using javascript

Sometimes it is useful to display a confirmation message before processing any action. Some application often asks for confirmation before doing something irreversible, like deleting content. 
the user to conform once again the deleting process. Here the user can change his mind and can cancel the operation or conform his action by clicking the submit button.

function confirmDelete(item){
 var strMsg = "Are you sure you want to delete this "+item+" ? ";
 var intAgree = confirm(strMsg);
 if (intAgree)
  return true ;
 else
  return false ;
}


Pass an array from an HTML form using Hidden field

It is simple way to pass your array using hidden field of form and get to another side  where you want to use this array's value


Snippet

Create Array

$arrNodeIds = array();
foreach ($data as $k => $objNode) {
$arrNodeIds[] = $objNode->nid;
}

Assign array to hideen field of form
<form method="post" action="/ess_upload/save_images">
<input type="hidden" name="hdnArrNodeIds" value="">
</form>

Get value from other side

$arrNodeIds = unserialize(urldecode($_POST["hdnArrNodeIds"]));
foreach($arrNodeIds as $intNodeId){
    echo $intNodeId;
}

Check Node is Exists In Drupal

It is good way to check Node is exists or not bellow example code would be helpful 

In this example , If node is exists in our database, then It will be deleted. otherwise give a error message and redirect to perticular page.

Example :
  $bolIsNodeAvail = node_load(array('nid' => $intNodeId)); 
  if($bolIsNodeAvail != false)
  {
        node_delete($intNodeId);  
  }else{
        drupal_set_message(t("node id is not exists."), 'error');  
  }
  drupal_goto('ess_upload/album_images');
 

Insert and Update Record using drupal_write_record()

It saves a record to the database based upon the schema.

you can simply call the new drupal_write_record function telling it what database table to write to and the information to write and the function will do the rest. SO you'll find yourself writing less and less of those long db_query insert and update commands!

Insert Record To Table
This would insert all the data in the $node object into the node database table.

drupal_write_record('node', $node);

Example :
$objFile = new stdClass();
$objFile->uid = $uId;
$objFile->filemime = $arrFile['str_file_mime'];
$objFile->filesize = $arrFile['int_file_size'];
$objFile->status = FILE_STATUS_PERMANENT;
$objFile->timestamp = time();
drupal_write_record('files', $objFile);


Update Record In Table
This would update the node in the node database table with the data in the $node object 
where nid is equal to the $node->nid

drupal_write_record('node', $node, 'nid')


Example :
$strFileExtension = getFileExtension($arrFile['str_orgin_file_name']);
$strFileNewName = $objFile->fid.".".$strFileExtension;
$objFile->filename = $strFileNewName;
$objFile->filepath = $arrFile['str_rel_file_path'].$uId.DIRECTORY_SEPARATOR.$strFileNewName;
drupal_write_record('files', $objFile,'fid');

How to do saved Node and get that node Id

I was trying to create a new node programatically by inserting information in node, I used below snippet.

  Saved Node

  $objNode = new StdClass();
  $objNode->title = utf8_encode($strTitle);
  $objNode->type = 'album_image';
  $objNode->status = 1;
  $objNode->moderate = 0;
  $objNode->promote = 0;
  $objNode->sticky = 0;
  $objNode->revision = 0;
  $objNode->comment = 0;
  $objNode = node_submit($objNode);

  $intTimestamp = time();
  $objNode->uid = $uId;
  $objNode->created = $intTimestamp;
  $objNode->changed = $intTimestamp;
  node_save($objNode);
 

  How to get the nid after node_save() in drupal 6

  Previously node_save() returned the $nid but not anymore... so what do we do? 

  It's simple. You have just saved a variable as your node. in our case we use $objNode 

  intInsertedNodeID = $objNode->nid;

  It is easy to use 

Pass Finnish character to ajax request and get junk character (skandinavian charachters)

I have found some of character passes ajax through php file and get stange output (skandinavian charachters)

I pass data with escape() function [escape(output)]. see in bellow snippet

Passed such string to ajax call:
Klikkaa lisätäksesi
tekstiä

and get result of such string
Klikkaa lis�t�ksesi
teksti�

what's problem occure in this script

var callBackActUrl = "dvk.eirikvae.aum"
var textdata = "text="+escape(output);
jQuery.ajax({
type: "POST",
url: callBackActUrl,
data: textdata,
cache: false,
success:function(responseText){
alert(responseText);

}
});


Solution :
I had read lot of artical on google and find solution for. I passed data in ajax using escape function, we replaced escape() function with
encodeURIComponent() and it is working proper.

var textdata = "text="+encodeURIComponent(output);

This method will encode certain chars that would normally be recognized as special chars for URIs.

How to disable resizable textarea in drupal

I am using the profile module but I remove the resizable textarea on the frontend of website.

There doesn't seem to be an option to enable/disable in drupal or even profile module so I tried implementing this:

Snippet :

function mymodule_form_alter(&$form,$form_state, $form_id){
if (
$form_id == 'user_register'){
$form['account_information']['profile_address']['#resizable'] = false;
}
}


It should only point to the profile module. I Couldn't find any other the right code.