0

I'm using editable fields, so I can edit the fields on node display page (e.g. at node/123). I want to add a submit function, so that I can add other process every time the user edit the field. My problem is my custom submit function is not being called.

Below is the code I'm using:

function apws_extras_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'editablefields_form_node_field_apws_batch_completed_field':
      if ($form['type']['#value'] == 'apws_batch') {
        $form['#validate'][] = 'apws_extras_batch_completed_form_validate';
        $form['#submit'][] = 'apws_extras_batch_completed_form_submit';
      }
      break;
  }
}

function apws_extras_batch_completed_form_validate(&$form, &$form_state){
  // Check if this field is set.
  // Code for validation here.
}

function apws_extras_batch_completed_form_submit(&$form, &$form_state) {
  drupal_set_message('Submit is working');
}

enter image description here

| improve this question | | | | |
  • Please provide a sample code how you're trying to add a custom submit handler, that will help find the issue and provide better solution. – Yogesh Dec 13 '16 at 5:05
  • Hi @yogesh, I have edited the body and added the code. – Marvin Laton Dec 13 '16 at 5:26
1

You can try this:

function apws_extras_form_alter(&$form, &$form_state, $form_id) {
    switch ($form_id) {
case 'editablefields_form_node_field_apws_batch_completed_field':
      if ($form['type']['#value'] == 'apws_batch') {
        $form['#validate'][] = 'apws_extras_batch_completed_form_validate';
        //$form['#submit'][] = 'apws_extras_batch_completed_form_submit';
        $form['actions']['submit']['#submit'][] = 'apws_extras_batch_completed_form_submit';
      }
      break;
  }
}

function apws_extras_batch_completed_form_validate(&$form, &$form_state){
  // Check if this field is set.
  // Code for validation here.
}

function apws_extras_batch_completed_form_submit(&$form, &$form_state) {
  drupal_set_message('Submit is working');
}
| improve this answer | | | | |
  • // Attach our custom submit handler. $form['actions']['publish']['#submit'][] ='my_module_node_article_form_submit'; – Atikrant Upadhye Dec 13 '16 at 6:05
  • Hi @atikrant, it still not working. :( – Marvin Laton Dec 13 '16 at 6:26
  • @MarvinLaton: Have checked by clearing drupal cache? Still it is not working then print the '$form' and post your array here. – Atikrant Upadhye Dec 13 '16 at 9:20
  • Yes I have clear cache but the submit handler is not working. I have edited the body and attached the screenshot the array of the $form. – Marvin Laton Dec 14 '16 at 1:39
  • @MarvinLaton: EditableFields module is having bugs. Please apply patch for that module and then check. – Atikrant Upadhye Dec 14 '16 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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