0

Could you please help me with the following task? I need to make the existing field (name Clarify, type select - "clarification required/clarification isn't required") to be editable from display view (not on the Edit tab) and I need to place this field next to Comment field (see the screenshot).

I'm trying to use hook_alter_form in the following way, but with no luck. I know the below code is wrong and I need a little help to know which way to go.

function custom_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'comment_node_support_ticket_form') {
    $form['field_clarify'] = array(
      '#type' => 'select',
      '#title' => 'Clarify',
    );

    $form['#validate'][] = 'custom_support_comment_submit';
  }
}

function custom_support_comment_submit($form, &$form_state) {
  $node = node_load($form_state['values']['nid']);
  $node_wrapper = entity_metadata_wrapper('node', $node);
  $node_wrapper->field_clarify->set($form_state['values']['field_clarify']);
  $node_wrapper->save();  
}

enter image description here

1 Answer 1

0

First, you need 'options' => array('clarification required', 'clarification isn\'t required') for select because you need options. Then you need to make sure your module name is custom (unless you don't want to expose your module name). Also, you pass your function name to $form['#validate'][] but it ends with _submit (it should be _validate).

There are what I found at the first glance. I didn't check the code.

3
  • Something like this? function custom_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'comment_node_support_ticket_form') { $form['field_clarify'] = array( '#type' => 'select', '#title' => 'Clarify', '#options' => array('clarification required', 'clarification isn\'t required' ); $form['#submit'][] = 'custom_support_comment_submit'; } }
    – jksport
    Commented Apr 1, 2015 at 7:16
  • function custom_support_comment_submit($form, &$form_state) { $node = node_load($form_state['values']['nid']); $node_wrapper = entity_metadata_wrapper('node', $node); $node_wrapper->field_clarify->set($form_state['values']['field_clarify']); $node_wrapper->save(); }
    – jksport
    Commented Apr 1, 2015 at 7:16
  • Yeah, you did it right :)
    – Kartagis
    Commented Apr 1, 2015 at 7:21

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.