0

I am adding a config option to all content types. I have textfield and checkbox now.

How to SAVE what I write in the textfield and state of checkbox when I hit submit?? Do I need to alter submit function for this form?

function neil_misc_form_node_type_form_alter(&$form, $form_state) {
  global $user;
  if (isset($form['type'])) {
    $form['followbtn'] = array(
      '#type' => 'fieldset',
      '#title' => t('Follow Button settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#group' => 'additional_settings',
    );

$form['followbtn']['comment'] = array(
  '#type' => 'textfield',
  '#title' => t('Email address to send updates to'),
  '#default_value' => $user->mail,
);

$form['followbtn']['followbtn_default_mode'] = array(
  '#type' => 'checkbox',
  '#title' => t('Add Follow button to this Node Type?'),
  '#default_value' => variable_get('comment_default_mode_' . $form['#node_type']->type, ADD_FOLLOWBTN),
);
  }
}

1 Answer 1

0

You can add a custom submit handler for your custom group of options and controls. For example on the base form you add an additional #submit value and check your own custom fields:

$form['#submit'][] = array('mymodule_form_followbtn_custom_submit');

if needed you can validate is form element independantley:

$form['followbtn']['followbtn_default_mode']['#element_validate'] = 'mymodule_followbtn_element_validate_default_mode';

or ...

$form['followbtn']['comment'] = 'mymodule_followbtn)element_validate_comment';

Then your submit function just does your processing (after elements validate on submission:

function mymodule_form_followbtn_custom_submit($form, &$form_state) {
  // save your stuff ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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