function _webform_node_autocomplete_validate in Webform Node Element 7
Same name and namespace in other branches
- 6 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 229 
- Webform module node component.
Code
function _webform_node_autocomplete_validate(&$element) {
  $nid = $element['#value'];
  $preg_matches = array();
  $match = preg_match('/\\[id: (\\d+)\\]/', $nid, $preg_matches);
  if (!$match) {
    $match = preg_match('/^id: (\\d+)/', $nid, $preg_matches);
  }
  if ($match) {
    $nid = $preg_matches[1];
  }
  if (is_numeric($nid)) {
    $node = db_query('SELECT nid FROM {node} WHERE nid = :nid', array(
      ':nid' => $nid,
    ))
      ->fetchObject();
  }
  else {
    $node = db_query('SELECT nid FROM {node} WHERE LOWER(title) = LOWER(:title)', array(
      ':title' => $nid,
    ))
      ->fetchObject();
  }
  if ($node) {
    $element['#value'] = $node->nid;
  }
  return;
}