I currently have a custom module which calls a submit custom validation function. I am trying to update a value after the validation is run. Basically, if a value is present, update a field to say “Yes”.
function sitefuncs_form_alter(&$form, &$form_state, $form_id){ if( $form_id == 'stage_2_node_form') { $form['actions']['submit']['#submit'][] = 'sitefuncs_custom_submit'; } } // end hook_form_alter() function sitefuncs_custom_submit($form, &$form_state) { $banned = array( 'better cures', 'better nhs', 'because it', 'so what' ); if (in_array($form_state['values']['field_stage_two_question_one']['und'][0]['value'], $banned)) { // if a banned word is the value of the input $form_state['values']['field_stage_complete_text']['und'][0]['value'] = "No"; // set the value of the text input to No } else { $form_state['values']['field_stage_complete_text']['und'][0]['value'] = "Yes"; $messages = drupal_get_messages('status'); drupal_set_message(t('Your changes have been saved.')); } }
If anyone has any idea why the $form_state
isn’t updating the fields after I save the node, any help would be great!
Sponsored by SupremePR