Drupal 7 field cache problems

2 replies [Last post]
Wallace9879
Offline
Last seen: 7 years 34 weeks ago
Joined: 2011-01-25

Hello, I am working on a element and am having a lot of problems.

I have a form which has a hidden custom element on it. The element is basically a hidden status, which I am using to read to perform other functions. When the form is initially opened, the field defaults to "Not in Review".

After save, I have other code which appropriately changes the value in the table to "In Review" using the following code within a function.
db_update('field_data_field_proj_status')
->fields(array( 'field_proj_status_project_status_value' => 'In Review'))
->condition('entity_id', $nid)
->execute();

I can double check the database directly and the field appropriately says "In Review"

However, when I load the content page again (view) the field says "Not in Review". Then when I "Edit and Save" it automatically changes it again to "Not in Review".

I think this is happening because the content seems to be caching on the user side.

If I perform the same procedures by Creating content and checking database to confirm value was appropriately changed to "In Review" that works. Then if I hit "Empty Cache" button, the cache clears. Then if I view the content it appropriately says "In Review" and if I edit and save, the value never changes to "Not in Review".

So I know this is a cache problem.

Does anyone know code that I can use which will not cache a specific field? Or how I can prevent this problem?

Basically I need a field which I can change automatically after save. Then if it is edited and saved again, I cannot have it revert back to the original status.

Here is the code of how I am building the element through the custom form.module file within the widget.form
$element['project_status_value'] = array(
'#type' => 'hidden',
'#title' => t('Project Status:'),
'#default_value' => isset($items[$delta]['project_status_value']) ? $items[$delta]['project_status_value'] : 'Not in Review',
);

Thanks in advance

Chris Shattuck
Offline
Last seen: 7 weeks 1 day ago
Joined: 2009-08-16
Hi there, It looks like this

Hi there,

It looks like this field is part of a node, in which case you would probably want to use node_save() after loading with node_load() and making adjustments, instead of using the Database API. This will trigger the kind of actions that take place behind the scenes when you do something like submit the node edit form.

Let me know if this points you in the right direction.

Cheers!
Chris

Chris Shattuck
Offline
Last seen: 7 weeks 1 day ago
Joined: 2009-08-16
Hey Jen! I don't have any

Hey Jen!

I don't have any ideas for you right now since it's not something I've been working on recently, but if I get a chance to dive in, I'll be sure to post back here and also send you a quick email.

Cheers!
Chris

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:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
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?
user
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.