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

  • SEARCH
  • Home
  • 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 8667697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:01:57+00:00 2026-06-12T18:01:57+00:00

I have a custom form that creates a new user and fills in a

  • 0

I have a custom form that creates a new user and fills in a number of custom fields for that user. One of these fields is a custom image (not the system avatar image).

I can get the image uploaded to the server through the form, but can’t get it into the appropriate field. Here is my (custom module) code so-far.

function newacc_freebusiness_form($form, &$form_state) { 

$form['bussimage'] = array(
  '#title' => t('Upload an image that shows off your business.'),
  '#type' => 'managed_file',
  '#description' => t('Max size of 3Mb and filetype of jpg jpeg or png'),
  '#upload_location' => 'public://bussimages/',
  '#upload_validators' => array(
    'file_validate_extensions' => array('png jpg jpeg'),
    'file_validate_size' => array(3*1024*1024),
      ),
  '#required' => TRUE,
);
 $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
 );

 $form['#validate'][] = 'newacc_freebusiness_validate';

 return $form;
 }
 function newacc_freebusiness_validate($form, &$form_state) {
  $bussimage = $form_state['values']['bussimage'];
  $file = file_load($bussimage);
  $bussimage = image_load($file -> uri);
  image_save($bussimage);
  $bussimage = image_load($file -> uri);
  $edit = array(
    'name' => 'name',
    'mail' => 'mail@mail.com',
    'status' => 0,
    'language' => 'en',
    'init' => 'mail@mail.com',
    'roles' => array(8 => 'Promoter'),
    'field_business_image' => array(        
    'und' => array(
        0 => array(
            'value' => $bussimage,
            ),
          ),
        ),
        );
        user_save(NULL, $edit);
 }

This is throwing the error message:

Notice: Undefined index: fid in file_field_presave() (line 219 of /var/www/drupal_site/modules/file/file.field.inc).

I have tried so many tricks now and googled so long that I can’t even explain what I have and haven’t tried anymore!

Any help please.

  • 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-12T18:01:59+00:00Added an answer on June 12, 2026 at 6:01 pm

    OK – solved this. The clue was in the error message and the solution was very simple! Here is the code:

    function newacc_freebusiness_form($form, &$form_state) { 
    
        $form['bussimage'] = array(
        '#title' => t('Upload an image that shows off your business.'),
        '#type' => 'managed_file',
        '#description' => t('Max size of 3Mb and filetype of jpg jpeg or png'),
        '#upload_location' => 'public://bussimages/',
        '#upload_validators' => array(
        'file_validate_extensions' => array('png jpg jpeg'),
        'file_validate_size' => array(3*1024*1024),
        ),
        '#required' => TRUE,
        );
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit',
    );
    
    $form['#validate'][] = 'newacc_freebusiness_validate';
    
    return $form;
    }
    function newacc_freebusiness_validate($form, &$form_state) {
        $bussimage = $form_state['values']['bussimage'];
        $file = file_load($bussimage);
        $edit = array(
        'name' => 'name',
        'mail' => 'mail@mail.com',
        'status' => 0,
        'language' => 'en',
        'init' => 'mail@mail.com',
        'roles' => array(8 => 'Promoter'),
        'field_business_image' => array(        
            'und' => array(
                0 => array(
                'fid' => $file -> fid,
            ),
          ),
        ),
        );
    user_save(NULL, $edit);
    }
    

    All Drupal was looking for was the file fid in the array. Don’t know why I initially assumed it had to be more complicated than this.

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

Sidebar

Related Questions

I have one main windows form and within that form I have custom controls
I have a client that wants to have a custom form added as a
I have a custom control that can be added multiple times to a form.
Check out this jsbin . I have a form with a custom button that
I have a list within Sharepoint, using a custom new form I have added
So I have a form that I want the user to use to update
I have a Windows form which hosts a custom User Control. This User Control
In my application I have a Form that for one of the top level
Let's say you have a custom form MyForm : Form and want to run
I have made a custom form in a module where I have used a

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.