Emir Memic
Emir Memic

Reputation: 270

Drupal 7 hook_form_submit

I'm trying to modify the file description field inside the form_alter function by using the form_submit function.

In my hook_FORM_ID_alter() function I'm assigning a new data array as:

function hook_FORM_ID_alter(&$form, &$form_state) {
  $field['data']['description'] = 'some value';
  $form['field_upload']['und'][0]['#default_value'] = $field;
}

Then in my hook_form_submit() function, I'm trying to pass the value into another function at the same time store it inside my field_upload_description field

function hook_form_submit($form, &$form_state) {
  $values = $form_state['values'];
  $doc = $values['data']['description'];
  $result = some_other_function($doc);
}

Nothing happens. As a matter of fact, when I go back to edit the node, the file is no longer attached in the file field.

I'm not sure what I'm missing.

Upvotes: 0

Views: 9282

Answers (2)

Astucieux
Astucieux

Reputation: 169

You did a mistake in the declaration of the hook function, so your first function is probably not called !!

  1. The name of the function is : hook_form_FORM_ID_alter
  2. Be careful, in Drupal 7, the fonction uses a third argument : $form_id, whereas this third argument is not in the Drupal 6 equivalent function.

The good function declaration (for Drupal 7):

/**
 * Implements hook_form_FORM_ID_alter() for FORM_ID().
 */
function hook_form_YOUR-FORM-ID_alter(&$form, &$form_state, $form_id) {

}

Upvotes: 1

hugronaphor
hugronaphor

Reputation: 985

You need to change $form_state values.

Upvotes: 2

Related Questions