0

Using hook_form_alter(), I created 4 form fields. When saving a node, I want to extract data from them and transferred to a standard field.

Using foreach(), I can form a string and then transfer it to the standard field, but how do I get the data from the form input, while saving material?

I use hook_node_presave($node) but it already takes $node as argument, in which there are no custom fields. I do not know how to transfer them here and already work with hook_node_presave().

$form['field_cadastral_num'] = array(
    '#type' => 'fieldset',
    '#title' => 'test',
    '#attributes' => array(
        'class' => array(
            'field-type-text',
            'field-name-property_node_form'
        ),
    ),
  '#weight' => $instance['widget']['weight'],
);  
$form['field_cadastral_num']['cell'][] = array(
  '#type' => 'textfield',  
  '#default_value' => '', 
  '#size' => 3, 
  '#maxlength' => 3,
  '#name' => 'kadastr[0]',
  '#value' => ''
);
$form['field_cadastral_num']['cell'][] = array(
  '#type' => 'textfield',  
  '#default_value' => '', 
  '#size' => 3, 
  '#delta' => 3, 
  '#maxlength' => 3,
  '#name' => 'kadastr[1]',
  '#value' => '',
  '#prefix' => ':'
);  
$form['field_cadastral_num']['cell'][] = array(
  '#type' => 'textfield',  
  '#default_value' => '', 
  '#size' => 6, 
  '#maxlength' => 6,
  '#name' => 'kadastr[2]',
  '#value' => '',
  '#prefix' => ':'
);
$form['field_cadastral_num']['cell'][] = array(
  '#type' => 'textfield',  
  '#default_value' => '', 
  '#size' => 3, 
  '#maxlength' => 3,
  '#name' => 'kadastr[3]',
  '#value' => '',
  '#prefix' => ':'
);  
0

I would suggest you create the 'cell' fields through the Drupal UI (admin/structure/types/manage/xxxx/fields) so they are registered correctly as part of the content type, then their values will be available in hook_node_presave().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.