I created a panel, added Node Add Form context and placed some fields on the panel. Now when I fill in the form with errors (like skipping required fields) and submit it, the page reloads but without marks on erroneous fields. The reason is that the function which sets appropriate classes skips such fields:

function _form_set_class(&$element, $class = array()) {
  ...
  if (isset($element['#parents']) && form_get_error($element) !== NULL && !empty($element['#validated'])) {
    $element['#attributes']['class'][] = 'error';
  }
}

as they don't have '#validated' attribute since the form has not been validated.

From my observations this happens due to they way ctools works with form contexts:
* for the first time the form is created (and validated) after ctools_context_handler_get_render_handler() call (/*1*/ line)
* for the second time the form is created (but not validated!) from ctools_context_handler_render_handler call (/*2*/ line)

function ctools_context_handler_render($task, $subtask, $contexts, $args) {
...
  $id = ctools_context_handler_get_render_handler($task, $subtask, $handlers, $contexts, $args); /*1*/
  if ($id) {
    return ctools_context_handler_render_handler($task, $subtask, $handlers[$id], $contexts, $args); /*2*/
  }
...
}

My quick solution is to force form validating in ctools_context_create_node_add_form().

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

OnkelTem’s picture

Status: Active » Needs review
FileSize
1.18 KB
Chris Matthews’s picture

The 4 year old patch to node_add_form.inc still applies cleanly to the latest ctools 7.x-1.x-dev and if still applicable needs review.

Checking patch plugins/contexts/node_add_form.inc...
Hunk #1 succeeded at 71 (offset -1 lines).
Applied patch plugins/contexts/node_add_form.inc cleanly.