Working with $form_state

2 replies [Last post]
Last seen: 10 years 48 weeks ago
Joined: 2011-03-30

I am trying to test whether or not a field has been changed since the last submission. If it has changed I want to track the changes of this specific field. I know how to pull the $form_state['values'], but can you help me on pulling the initial value or the stored value of the field?

I have a content type of Wells that I would like to track the status of each of them as they are updated. Anytime the well status is changed I want to store the user, date, status, node id. I don't want to store it every time the node is saved, only when the status is changed. Then, I will show a history of status changes.

Can you point me in the right direction on how to compare the previous value to the newly submitted value. Also, the status is a taxonomy term, so if you could give me an idea of how to work with taxonomy terms it would help as well.

Chris Shattuck
Last seen: 10 weeks 4 days ago
Joined: 2009-08-16
Good questions! Let me give

Good questions!

Let me give you a few hints that will hopefully point you in the right direction.

You can use hook_node_presave() to perform an action before the node is saved. What you'd probably do is use node_load() to load the existing node, and then hook_node_presave() will have the altered node data. You can then use something like the devel's module dpm(), print_r() or a debugger to find the values within those objects that you want to compare. The taxonomy terms will be part of the node object.

Once you've compared the values and found that they're different, you can save the change data, either in a custom table or as a node.

Let me know if this makes sense. It's kind of a tricky operation you're doing, so there may be some learning required to really execute it the way you'd like.


Last seen: 10 years 48 weeks ago
Joined: 2011-03-30

That is what I was looking for. I will see if I can implement it. Thanks!

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:

Contact us

Below are the supported keyboard shortcuts for our video player.

Start / stop video
Go to next video
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
Jump to a percentage (2 is 20%, for example)
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
1 month
6 months
10% off
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.