You are here

function _webform_node_autocomplete_validate in Webform Node Element 6

Same name and namespace in other branches
  1. 7 components/node.inc \_webform_node_autocomplete_validate()

Helper to pull apart a possible ctools node autocomplete submission.

This is lifted verbatim from the ctools_node_content_type_edit_form_validate() function at http://drupalcontrib.org/api/drupal/contributions--ctools--plugins--cont...

Parameters

&$element: A reference to the form element submitted by the user.

1 call to _webform_node_autocomplete_validate()
_webform_edit_validate_node in components/node.inc
Element validation callback. Ensure a valid node ID was entered.

File

components/node.inc, line 221
Webform module node component.

Code

function _webform_node_autocomplete_validate(&$element) {
  $nid = $element['#value'];
  $preg_matches = array();
  $match = preg_match('/\\[nid: (\\d+)\\]/', $nid, $preg_matches);
  if (!$match) {
    $match = preg_match('/^nid: (\\d+)/', $nid, $preg_matches);
  }
  if ($match) {
    $nid = $preg_matches[1];
  }
  if (is_numeric($nid)) {
    $node = db_result(db_query("SELECT nid FROM {node} WHERE nid = %d", $nid));
  }
  else {
    $node = db_result(db_query("SELECT nid FROM {node} WHERE LOWER(title) = LOWER('%s')", $nid));
  }
  if (!empty($node)) {
    $element['#value'] = $node;
  }
  return;
}