0
votes

I am using mymodule_form_alter hook

I want to change values of fields of form after submit.

Anybody have an idea how to do this. I am using drupal7.

Here is the code

function check_domain_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case "user_register_form":
      $form['#submit'][] = 'check_domain_user_register_form_submit';
      break;
  }
}

function check_domain_user_register_form_submit($form, &$form_state) {
  $form_state['input']['profile_main']['field_firm_company_name']['und'][0]['value']='test';
}
1

1 Answers

3
votes

A submit handler is called too late in the process to do this...the values field values will already have been saved. Also you want to use $form_state['values'], not $form_state['input'].

If you move your code to a validate handler you should get more luck:

function check_domain_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case "user_register_form":
      $form['#validate'][] = 'check_domain_user_register_form_validate';
      break;
  } 
}

function check_domain_user_register_form_validate($form, &$form_state) {
  $form_state['values']['profile_main']['field_firm_company_name']['und'][0]['value']='test';
}