Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7885973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:12:18+00:00 2026-06-03T05:12:18+00:00

I started to create a new content type with modules Field Group and Field

  • 0

I started to create a new content type with modules Field Group and Field Collection and it’s worked !

But, I would like to add autocomplete fields in my form and I don’t find how to do this. Maybe using a hook_form_alter however I can’t add my custom fields in my field collection.

You know how to do this ?

Thanks a lot

PS: I work with D7

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:12:19+00:00Added an answer on June 3, 2026 at 5:12 am

    To add an auto_complete to a from field, you need to do the following:

    1st: use hook_for_alter() to add the auto_complete path to the text field

    function YOUR_MODULE_form_alter(&$form, &$form_state, $form_id)
    {
        if($form_id == "YOUR-CONTENT-TYPE_node_form")
        {
            $form['field_YOUR-FIELD']['und'][0]['value']['#autocomplete_path'] = 'my-module/autocomplete/path';
        }
    }
    

    2nd: use hook_menu() to define the menu callback you passed as the #autocomplete_path property to the field

    function YOUR_MODULE_menu()
    {
        $items = array();
        $items['my-module/autocomplete/path'] = array(
        'page callback'     => 'your_module_autocomplete_callback',
        'access callback'   => TRUE,
        'weight'            => 1,
        'type'              => MENU_CALLBACK,
        );
        return $items;
    }
    

    3rd and last: add you menu callback function which returns the items to the textfield

    function your_module_autocomplete_callback($string)
    {
        $items = array();
        $query = db_select('node', 'n');
        $value = $query->fields('n', array('title'));
        $value = $query->condition(db_and()->condition('n.type', 'YOUR_CONTENT_TYPE')->condition('title', '%' . db_like($string) . '%', 'LIKE'))->orderRandom()->execute();
    
        $i = 0;
        foreach ($value as $val)
        {
            $items[$val->name] = check_plain($val->name);
        }
        print drupal_json_output($items);
        exit();
    }
    

    Hope this helps… Muhammad.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to drupal (started yesterday), I have created a content type called
I'm new to ruby and started to create my *nd toy app. I: Created
I started a grails application by grails create-app. For modularity, I feel like it
I wanted to create jquery plugin & started off creating a sample jquery plugin...But
Im very new to this android development.I just started to create a hello world
What is the purpose of getSocket(type,persistence_id,callback) in zeromq? Will it create a new socket
So, I've started to create some Ruby unit tests that use Selenium RC to
thanks in advance for the replies.... I have started to create a network topology
I started to do some experimentation with iisnode and expressjs to create a REST
I want to create a keyboard and mouse hook which will be started as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.