I have a function in my e-commerce website that allow users to create own stores, i need to add dynamic field (select list) contain the stores created by the logged user when he add new product to assign this product with store.

i try to add field on the content type 'product' but i found that drupal save the values in the database. What is he best method that resolve my problem?

1 Answer 1


I'm not sure what you are trying to do. But if you are trying to add a new field programmatically, below is a code snippet that can get you started.

    $myField_name = "my_new_field_name";
    if(!field_info_field($myField_name)) // check if the field already exists.
        $field = array(
            'field_name'    => $myField_name,
            'type'          => 'image',

        $field_instance = array(
            'field_name'    => $myField_name,
            'entity_type'   => 'node',
            'bundle'        => 'CONTENT_TYPE_NAME',
            'label'         => t('Select an image'),
            'description'   => t(''),
            'widget'        => array(
                'type'      => 'image_image',
                'weight'    => 10,
            'formatter'     => array(
                'label'     => t('label'),
                'format'    => 'image'
            'settings'      => array(
                'file_directory'        => 'photos', // save inside "public://photos"
                'max_filesize'          => '4M',
                'preview_image_style'   => 'thumbnail',
                'title_field'           => TRUE,
                'alt_field'             => FALSE,
        drupal_set_message("Field created successfully!");

Hope that works


  • Function name ?
    – GoodSp33d
    Mar 20, 2012 at 13:52
  • My Problem is the field can't take different value for each user? for example: i have a fiel for name "field_mystore" is select list type. user1 show the field store contain his store list (user1 store1, user1 store2) user2 show the field store contain his store list (user2 store1, user2 store2) is it possible do code my idea?
    – Tayba
    Mar 20, 2012 at 14:12
  • Use any event you want. Bind it to hook_install() or bind it in any button click. Mar 20, 2012 at 14:12

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.