You are here

function webform_components_form_validate in Webform 7.4

Same name and namespace in other branches
  1. 5.2 webform_components.inc \webform_components_form_validate()
  2. 6.3 includes/webform.components.inc \webform_components_form_validate()
  3. 6.2 webform_components.inc \webform_components_form_validate()
  4. 7.3 includes/webform.components.inc \webform_components_form_validate()

Validate handler for webform_components_form().

1 string reference to 'webform_components_form_validate'
webform_components_form in includes/webform.components.inc
The table-based listing of all components for this webform.

File

includes/webform.components.inc, line 298
Webform module component handling.

Code

function webform_components_form_validate($form, &$form_state) {

  // Check that no two components end up with the same form key.
  $duplicates = array();
  $parents = array();
  if (isset($form_state['values']['components'])) {
    foreach ($form_state['values']['components'] as $cid => $component) {
      $form_key = (string) $form['#node']->webform['components'][$cid]['form_key'];
      if (isset($parents[$component['pid']]) && ($existing = array_search($form_key, $parents[$component['pid']], TRUE)) && $existing !== FALSE) {
        if (!isset($duplicates[$form_key])) {
          $duplicates[$form_key] = array(
            $existing,
          );
        }
        $duplicates[$form_key][] = $cid;
      }
      $parents[$component['pid']][$cid] = $form_key;
    }
  }
  if (!empty($duplicates)) {
    $error = t('The form order failed to save because the following elements have same form keys and are under the same parent. Edit each component and give them a unique form key, then try moving them again.');
    $items = array();
    foreach ($duplicates as $form_key => $cids) {
      foreach ($cids as $cid) {
        $items[] = webform_filter_xss($form['#node']->webform['components'][$cid]['name']);
      }
    }
    form_error($form['components'], $error . theme('item_list', array(
      'items' => $items,
    )));
  }
}