views:

63

answers:

1

Lets say I have a cck field called foo. It is a text field with php input. Say the php code in foo field results in the value of 1,256 when computed. I need cck field called bar to pick up/obtain/have the VALUE (1,256) of cck field foo.


Node XYZ
Foo:*some php code*      ===>results in value of 1,256
Bar:1,256

If I just have cck field Foo in a node, it spits out the correct value, (1,256) but that field is the way our views are sorted; and views cant sort by a php field.

I tried to get computed_field.module to obtain its value, but it would spit out the php code, not the value.

Any ideas out there?

+2  A: 

You need to hook the node submit form, and add a submit handler

function moduleNameHere_form_nodeNameHere_node_form_alter(&$form, $form_state) {
             //Add handler
             $form['#submit'][] = 'moduleNameHere_submit_function';
}

then you create the handler that will get called on submit

function moduleNameHere_submit_function($form, &$form_state) {
   //Assign foo's value to variable
   $myValue = $form_state['values']['foo'];

   //Set bar to foo's variable
   $form_state['values']['bar'] = $myValue;

}
cinqoTimo
That worked perfectly when I integrated your code into my module that retrieves the ranks. Logically it makes perfect sense. Thank you very much for your help @cinqoTimo
picxelplay
@picxelplay - No problem. Welcome to Stackoverflow..
cinqoTimo
On first look, it was working. I tested it out with 3 nodes in a view. It was sorting correctly. I was sorting it by field Bar. I first did ascending, then descending; all worked fine. Then when I started adding more nodes, the results were not sorting. Any ideas?
picxelplay
If I go into a node edit, field foo is the php code (php filter on), and is also copied into field bar (php filter on). The text displayed inside of field bar is the php code from foo, and not the value of foo.
picxelplay

related questions