2
votes

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?

1
Do you mean "foo" obtains that value on submit, or before submit?tpow
Submit of the node? If that's what you mean, then on submit. I need Bar to ONLY have the value of 1256 (integers or text). I basically need the field to have the integers 1256 stored in the db. See, field Foo is a computed Alexa Traffic Rank number. It's php code that returns the number upon compute. This number can can stay that computed value in the database until It is recomputed. computed_field recomputed the value upon re-saving the node. (If that gives you more of an idea).picxelplay
And also I would be ok if field Bar somehow was able to scrape/extract the value, or just somehow read the value outputted, and not the code.picxelplay

1 Answers

2
votes

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;

}