I need to define a CCK field that contains data from a non-Drupal table called Customers; i would like the field to show the list of Customers and saving the id_customer inside the node. Is there a way to do it without having to create Customers as node?

1 Answer 1


Well, one of the possible ways to do that is to create a cck field of type integer and use "select list" as a widget. And then in your implementation of hook_form_alter you need to extract data from Customers table and populate the select with this data.

You might find the following piece of code useful:

function YOUR_MODULE_NAME_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'YOUR_CONTENT_TYPE_NAME_node_form') {
    $sql = 'SELECT id, name FROM Customers';
    $result = db_query($sql);
    $options = '';
    while($row = db_fetch_array($result)) {
      $options .= $row['id'] . "|" . $row['name'] . "\n";
    $form['#field_info']['field_YOUR_FIELD_NAME']['allowed_values'] = $options;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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