Posts Tagged drupal

Content_connected module in drupal.org

Content connected is a lightweight module which allow administer to know whether content is connected with some other content before it is about to be deleted from the system. So administer should know whether content should be deleted or not.

Content connected is also added as sub tab in node pages to view content connection with other contents. This can be restricted by permissions for different roles.

Content connection based on entity reference field and any textarea/long field for any content type.

Connected content is listed in a table where it can be identified how it is connected(Reference field or textarea/long field).

, ,

Leave a comment

Drupal webform/custom form render multiple times on same page

I needed to place the same form multiple times on a drupal page but still be unique so that FAPI would know which one was being submitted.

To do that, first thing we need to render the same form in our function with non-existing form_id as follow:-

————

$form = drupal_get_form(‘webform_client_form_’ . $webform_nid . ‘_’ . $nid, $node);
drupal_render($form);

* it means ‘webform_client_form_’ . $webform_nid . ‘_’ . $nid  form_id does not exists in the Drupal site. 

————

Then we need to define hook_forms function in module.

function hook_forms($form_id, $args) {
$forms = array();
if (strncmp($form_id, ‘webform_client_form_’, 20) === 0) {
$forms[‘webform_client_form_’ . $args[0]->nid] = array(‘callback’ => ‘webform_client_form_’ . $args[0]->nid);
}
return $forms;
}

This is an example for same webform rendering multiple times in same page. It will work for custom form as well. It will also do the trick to track which form is submitted.  It will do validate only the form where button is clicked.

,

Leave a comment

[SOLVED] [Drupal Webform] Altering a Webform’s submit button to an image causes it to stop working

[SOLVED] [Drupal Webform] Altering a Webform’s submit button to an image causes it to stop working

Styling a Webform is more or less like styling any other ordinary HTML form. Often you would like to change the style of the submit button and replace it with an image via code in your Drupal website. Although this is extremely easy it might cause the button to stop working, forcing it to reload and fail to show the confirmation message. If you are facing this problem while styling your Webform in your Drupal website read on to find the solution.  

,

Leave a comment

Disable form validation on ajax call in Drupal form

If you use multiple submit button in Drupal from and add ajax call to submit button then you ajax submit button will execute form default validate and submit function. To prevent it from calling those default function you just need to do two following steps.

1) rename my validation function from “myformname_validate” to “myformname_do_validate”. This caused my validate function to not be called during the ajax request.

2) attach the “myformname_do_validate” function to my submit button like so:

<?php
$form[‘submit’] = array(
‘#type’ => ‘submit’,
‘#value’ => t(‘Submit’),
‘#validate’ => array(‘myformname__do_validate’),
);
?>

, ,

Leave a comment

Saving node’s fields without saving the node itself

Drupal core function node_save() is used to save nodes and it is frequently used to programmatically alter and save nodes’ data, which includes fields (aka CCK fields) as well. If you want to update a field of a node you could do it like this,

<?php
$node = node_load($nid);
$node->field_fieldname[LANGUAGE_NONE][0][‘value’] = ‘some value’;
node_save($node);
?>

However, there may be a case when you might want to save a node’s field, but not the node itself. For example, you may not want to update the node’s timestamp for the last update, because you want it to be changed by human user activity only. In another case, you may not want to call node_save() and thus invoke chain reactions such as email notifications when the node is updated. These two cases are what actually happened to me.

A Drupal function field_attach_update() may save your day if you encountered a similar problem that I had. You could actually replace node_save() with field_attach_update(),

<?php
$node = node_load($nid);
$node->field_fieldname[LANGUAGE_NONE][0][‘value’] = ‘some value’;
field_attach_update(‘node’, $node);
?>

,

Leave a comment