I have two content types (job_post and application) linked using the node reference + node reference url nodes. When I click a link in a job_post node, a new application node is created, so that candidates can fill out their job application. My goal is to automatically copy the content of an cck email field from the referenced job_post node to a cck email field in the application node.
To achieve this,I have created the following module:
// Implementation of hook_perm()
function mymodule_perm() {
return array('copy cck field');
}
// Implementation of hook_node_api
function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
switch ($op) {
//if the node is inserted in the database
case 'prepare':
//if node is a job application
if($node->type == 'application') {
//get nid from referenced node (using url information
$item_nid = arg(3);
//load and build node content
$item_node = node_load($item_nid);
$item_node = node_build_content($item_node);
//retrieve data from cck email field in referenced job post node
$item_email = $item_node->field_job_email[0]['view'];
//display result in website to check if value is correctly loaded
dsm($item_email);
Unfortunately when I get this code dsm returns and empty value.
When I make the following changes to the code:
//retrieve data from cck email field in referenced job post node
$item_email = $item_node->field_job_email;
//display result in website to check if value is correctly loaded
dsm($item_email);
I get the following outcome in krumo:
... (Array, 1 element)
0 (Array, 2 elements)
email(string, 9 characters) aa@aa.com
safe (string, 9 characters) aa@aa.com
Any suggestion on how to load the content of the cck email address field (aa@aa.com) into a new field?
Thank you so much!