Wednesday, November 9, 2011
Wednesday, November 2, 2011
Drupal autocomplete suggestion click track
What I'm not sure how to do and can't seem to find online is have the form submit when a user clicks a suggestion instead of simply completing that field.
$(document).ready(function(){
Drupal.jsAC.prototype.select = function (node) {
this.input.value = $(node).data('autocompleteValue');
if(jQuery(this.input).hasClass('auto_submit')){
this.input.form.submit();
}
};
})
then on your form item add:
'#attributes' => array('class'=> array('auto_submit')),
$(document).ready(function(){
Drupal.jsAC.prototype.select = function (node) {
this.input.value = $(node).data('autocompleteValue');
if(jQuery(this.input).hasClass('auto_submit')){
this.input.form.submit();
}
};
})
then on your form item add:
'#attributes' => array('class'=> array('auto_submit')),
Tuesday, September 20, 2011
Drupal Create Free order
global $user;
$trial_id = variable_get('ls_free_trial_product', NULL);
$error_msg = FALSE;
if (!$trial_id)
$error_msg = 'The free trial product is not yet configured. Please contact an administrator.';
$node = node_load($trial_id);
$product = uc_product_load($node);
if (!$product)
$error_msg = 'There was an error finding the free trial product. Please contact an administrator.';
$product->nid = $node->nid; //we need to do this in order for the file downloads to work
$product->qty = 1;
$product->title = $node->title;
// Create the order and gather user information
$order = uc_order_new($user->uid, 'completed');
$order_id = $order->order_id;
if (!$user->uid) {
$names = split(' ', $form_state['values']['full_name']);
$last_name = array_pop($names);
$first_names = join(' ', $names);
$email = $form_state['values']['email'];
$company = $form_state['values']['company'];
} else {
$aid = _uc_addresses_get_default_address_id($user->uid);
$address = _uc_addresses_db_get_address($user->uid, $aid);
$first_names = $address->first_name;
$last_name = $address->last_name;
$email = $user->mail;
$company = $address->company;
}
// Populate the order
$order->products[] = $product;
$order->payment_method = 'free_order';
if (!isset($order->primary_email))
$order->primary_email = $email;
$order->billing_first_name = $first_names;
$order->billing_last_name = $last_name;
$order->billing_company = $company;
if (!$user->uid)
$order->data['new_user']['pass'] = $form_state['values']['password'];
// Complete the sale
uc_order_save($order);
uc_cart_complete_sale($order, TRUE);
// Submit the payment
uc_payment_enter($order->order_id, 'free_order', 0, 0, NULL, t('Checkout completed for a free order.'));
$order = uc_order_load($order_id);
if ($order->order_status == 'payment_received') {
$url = url('user/me/purchased-files');
drupal_set_message(t("Your free purchase has been processed. Go to My Downloads to find the link to your product."));
drupal_goto('user/me/purchased-files');
}
$trial_id = variable_get('ls_free_trial_product', NULL);
$error_msg = FALSE;
if (!$trial_id)
$error_msg = 'The free trial product is not yet configured. Please contact an administrator.';
$node = node_load($trial_id);
$product = uc_product_load($node);
if (!$product)
$error_msg = 'There was an error finding the free trial product. Please contact an administrator.';
$product->nid = $node->nid; //we need to do this in order for the file downloads to work
$product->qty = 1;
$product->title = $node->title;
// Create the order and gather user information
$order = uc_order_new($user->uid, 'completed');
$order_id = $order->order_id;
if (!$user->uid) {
$names = split(' ', $form_state['values']['full_name']);
$last_name = array_pop($names);
$first_names = join(' ', $names);
$email = $form_state['values']['email'];
$company = $form_state['values']['company'];
} else {
$aid = _uc_addresses_get_default_address_id($user->uid);
$address = _uc_addresses_db_get_address($user->uid, $aid);
$first_names = $address->first_name;
$last_name = $address->last_name;
$email = $user->mail;
$company = $address->company;
}
// Populate the order
$order->products[] = $product;
$order->payment_method = 'free_order';
if (!isset($order->primary_email))
$order->primary_email = $email;
$order->billing_first_name = $first_names;
$order->billing_last_name = $last_name;
$order->billing_company = $company;
if (!$user->uid)
$order->data['new_user']['pass'] = $form_state['values']['password'];
// Complete the sale
uc_order_save($order);
uc_cart_complete_sale($order, TRUE);
// Submit the payment
uc_payment_enter($order->order_id, 'free_order', 0, 0, NULL, t('Checkout completed for a free order.'));
$order = uc_order_load($order_id);
if ($order->order_status == 'payment_received') {
$url = url('user/me/purchased-files');
drupal_set_message(t("Your free purchase has been processed. Go to My Downloads to find the link to your product."));
drupal_goto('user/me/purchased-files');
}
Friday, July 22, 2011
Drupal 6 Set different custom message on node creation/update/delete
User the following module
Custom Submit Messages
http://drupal.org/project/csm
Custom Submit Messages
http://drupal.org/project/csm
Thursday, July 21, 2011
Friday, July 15, 2011
D6 converts URLs (http, ftp, email, ...) into hyperlinks.
$text field will contain the raw data which we need to convert into links.
$urlfilter_length = 72;
$text = $node_details->field_selling_external_prop_link[0]['value'];
$text = ' ' . $text . ' ';
$text = preg_replace_callback("!(|
|[ \n\r\t\(])((http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://)([a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+*~#&=/;-]))([.,?]?)(?=(| |
|[ \n\r\t\)]))!i", 'urlfilter_replace1', $text);
$text = preg_replace("!(|
|[ \n\r\t\(])([A-Za-z0-9._-]+@[A-Za-z0-9._+-]+\.[A-Za-z]{2,4})([.,?]?)(?=(| |
|[ \n\r\t\)]))!i", '\1\2\3', $text);
$text = preg_replace_callback("!(|[ \n\r\t\(])(www\.[a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+~#\&=/;-])([.,?]?)(?=(| |
|[ \n\r\t\)]))!i", 'urlfilter_replace2', $text);
$text = substr($text, 1, -1);
$text will contain the converted values.
Define below 3 function
function urlfilter_replace1($match) {
$match[2] = decode_entities($match[2]);
$caption = check_plain(urlfilter_trim($match[2]));
$match[2] = check_url($match[2]);
return $match[1] . ''. $caption .''. $match[5];
}
function urlfilter_replace2($match) {
$match[2] = decode_entities($match[2]);
$caption = check_plain(urlfilter_trim($match[2]));
$match[2] = check_plain($match[2]);
return $match[1] . ''. $caption .''. $match[3];
}
function urlfilter_trim($text) {
$urlfilter_length = 72;
return (strlen($text) > $urlfilter_length) ? substr($text, 0, $urlfilter_length) .'...' : $text;
}
$urlfilter_length = 72;
$text = $node_details->field_selling_external_prop_link[0]['value'];
$text = ' ' . $text . ' ';
$text = preg_replace_callback("!(
|
|[ \n\r\t\(])((http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://)([a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+*~#&=/;-]))([.,?]?)(?=(|
|[ \n\r\t\)]))!i", 'urlfilter_replace1', $text);
$text = preg_replace("!(
|
|[ \n\r\t\(])([A-Za-z0-9._-]+@[A-Za-z0-9._+-]+\.[A-Za-z]{2,4})([.,?]?)(?=(|
|[ \n\r\t\)]))!i", '\1\2\3', $text);
$text = preg_replace_callback("!(
|
|[ \n\r\t\)]))!i", 'urlfilter_replace2', $text);
$text = substr($text, 1, -1);
$text will contain the converted values.
Define below 3 function
function urlfilter_replace1($match) {
$match[2] = decode_entities($match[2]);
$caption = check_plain(urlfilter_trim($match[2]));
$match[2] = check_url($match[2]);
return $match[1] . ''. $caption .''. $match[5];
}
function urlfilter_replace2($match) {
$match[2] = decode_entities($match[2]);
$caption = check_plain(urlfilter_trim($match[2]));
$match[2] = check_plain($match[2]);
return $match[1] . ''. $caption .''. $match[3];
}
function urlfilter_trim($text) {
$urlfilter_length = 72;
return (strlen($text) > $urlfilter_length) ? substr($text, 0, $urlfilter_length) .'...' : $text;
}
Friday, July 8, 2011
Drupal 6 - Display a GMAP for a Location CCK field custom
My cck location filed is $node_details->field_map_location;
$lid = $node_details->field_map_location['0']['lid'];
if (is_numeric($lid)) {
$loc = location_load_location($lid);
$markertypes = variable_get('gmap_node_markers', array());
$markers = array();
$count = 0;
if (location_has_coordinates($loc)) {
$count++;
$markername = isset($markertypes[$node_details->type]) ? $markertypes[$node_details->type] : 'drupal';
if (module_exists('gmap_taxonomy')) {
$t = db_result(db_query('SELECT marker FROM {gmap_taxonomy_node} WHERE vid = %d', $node->vid));
if (!empty($t)) {
$markername = $t;
}
}
$markertitle = $node_details->title;
if (!empty($loc['name'])) {
$markertitle = $loc['name'];
}
$markers[] = array(
'latitude' => $loc['latitude'],
'longitude' => $loc['longitude'],
'markername' => $markername,
'offset' => $count-1,
'opts' => array('title' => $markertitle),
);
}
if (!empty($markers)) {
$macro = variable_get('gmap_location_block_macro_'. $node_details->type, '');
if (empty($macro)) {
$macro = variable_get('gmap_location_block_macro', '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]');
}
$map = gmap_parse_macro($macro);
$map['width'] = '100%';
$map['height'] = '300px';
$map['latitude'] = $node_details->location['latitude'];
$map['longitude'] = $node_details->location['longitude'];
$map['markers'] = $markers;
}
}
theme('gmap', array('#settings' => $map));
This will return the gmap with location marker.
$lid = $node_details->field_map_location['0']['lid'];
if (is_numeric($lid)) {
$loc = location_load_location($lid);
$markertypes = variable_get('gmap_node_markers', array());
$markers = array();
$count = 0;
if (location_has_coordinates($loc)) {
$count++;
$markername = isset($markertypes[$node_details->type]) ? $markertypes[$node_details->type] : 'drupal';
if (module_exists('gmap_taxonomy')) {
$t = db_result(db_query('SELECT marker FROM {gmap_taxonomy_node} WHERE vid = %d', $node->vid));
if (!empty($t)) {
$markername = $t;
}
}
$markertitle = $node_details->title;
if (!empty($loc['name'])) {
$markertitle = $loc['name'];
}
$markers[] = array(
'latitude' => $loc['latitude'],
'longitude' => $loc['longitude'],
'markername' => $markername,
'offset' => $count-1,
'opts' => array('title' => $markertitle),
);
}
if (!empty($markers)) {
$macro = variable_get('gmap_location_block_macro_'. $node_details->type, '');
if (empty($macro)) {
$macro = variable_get('gmap_location_block_macro', '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]');
}
$map = gmap_parse_macro($macro);
$map['width'] = '100%';
$map['height'] = '300px';
$map['latitude'] = $node_details->location['latitude'];
$map['longitude'] = $node_details->location['longitude'];
$map['markers'] = $markers;
}
}
theme('gmap', array('#settings' => $map));
This will return the gmap with location marker.
Subscribe to:
Posts (Atom)