It seems my love for Drupal and its Form API is always expanding, yep, kinda creepy sounding but to a web geek such as myself, it's perfectly normal to love a CMS and its API's!
In building my custom form I required an entity field which is present on user creation. Instead of duplicating the field, grabbing the current value and then saving the new value with an user_save() it's best practice to let Drupal handle the heavy lifting, since we don't want to duplicate tried and tested functionality or have to update the custom field should anything change to the entity field.
Right-o, let's...
The Drupal Subscriptions module notifies users on certain events. Usually when a new piece of content has been either saved or updated. Users can subscribe to specific nodes, terms or entire content types allowing them to keep up with the changes on the site. It's a great module.
This starts to break down however, when node references enter the picture. One of our recent Drupal 6 intranet projects required this feature and a custom solution had to be explored. The solution turned out to be pretty simple thanks to a extremely useful hook supplied in the Subscriptions module.
In this example,...
In a previous Drupal developer blog post, I discussed leveraging Ajax with Drupal's Form API. In this post we'll cover an alternative method in displaying dynamic content to your user - using Drupal's form states (conditional fields).
Using form states is really quite simple. It's just a Drupal Form API attribute and is used to display any kind of form content conditionally (conditional form fields). Commonly, a user may have some option, like a select list and different form fields may hide or show (using jQuery) based on the user's selection (often times referred to as dependent dropdowns...
Having a query builder like Views at your fingertips is fantastic on so many levels. I'm not going to get into my deep and semi-weird love affair with Views at this point in time, but I will show you how to programmatically display your Views display in code. This can be useful in a custom module, perhaps in a hook_node_view or maybe in one of your node or page templates.
In this example I'll add my View to my blog nodes. I'll just append my View to the bottom of the blog content. We'll want to use the views_embed_view() function to render our desired View display.
/**
* Implementation of...
I love Drupal's Form API. In just about every project we are either modifying or creating custom forms and thankfully, Drupal's Form API makes executing these tasks a fairly easy process. Everybody loves Ajax so in this tutorial we'll combine these two bits of awesomeness to produce some custom 'ajaxified' forms.
Lets start out with a hook_menu so we have a nice page for our example form. You'll see the "page callback" is the function "drupal_get_form" and our "page argument" is our function that will simply return our associative array.
/**
* Implements hook_menu().
*/
function...