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 8369565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:40:52+00:00 2026-06-09T13:40:52+00:00

I have created a content type with an associated image field. Each user is

  • 0

I have created a content type with an associated image field.
Each user is able to see a list of all the nodes of this content type and should be able to upload a new image in the appropriate field.
I’ve tried many solutions, but in the end I’m trying with a form and managed files.

In the page with the list of all the nodes I’m creating a lightbox with a form for each node.
Each form is created like this:

function coverupload_form($form, &$form_state, $uid, $relid) {

$form['#attributes']['id'] = 'coverup-'.$relid;

$form_state['storage']['rid'] = $relid;

$cliente = cataloghi_user_edit_get_cliente($uid);

$release = node_load($relid);

$form['cover'] = array(
    '#title' => 'Carica la cover per la release '.$release->title,
    '#description' => 'I file caricati devono avere estensione \'.jpeg\', risoluzione di 1440x1440 e dimensione massima di 5MB', 
    '#type' => 'managed_file',
    '#upload_location' => 'public://clienti/'.$cliente->title.'/cover',
    '#upload_validators' => array(
      'file_validate_extensions' => array('jpeg, jpg'),
      // Pass the maximum file size in bytes
      'file_validate_size' => array(5*1024*1024),
      'file_validate_image_resolution' =>array('1440x1440', '1440x1440'),
    ),
);


$form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('CARICA'),
);


return $form;
}

function coverupload_form_submit($form, &$form_state) {

$file = file_load($form_state['values']['cover']);
// Change status to permanent.
$file->status = FILE_STATUS_PERMANENT;
// Save.
file_save($file);


$nodo = node_load($form_state['storage']['rid']);


$nodo->field_release_copertina['und'][0] = (array)$file;

 if($nodo = node_submit($nodo)) { // Prepare node for saving
    node_save($nodo);
 }

}

All the forms have display: none, and when the user click on the cover upload button only the corresponding form is showed in the lightbox.

Well, everything works fine when the image is validated.
The problems start when the image is not validated (like if it’s below 1440x1440px).

If I check the lightbox with the inspector, the correct number of forms is generated but they all refer to the same node (so they all have id ‘coverup-17’ for example).

I have checked everything, and it seems like I pass the correct values to the form everytime, so I’m starting to think that it may be a problem connected with my poor understanding of forms.

Would it be better to try a different type of approach?

Thanks and sorry for if this is a bit messy…

  • 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-09T13:40:54+00:00Added an answer on June 9, 2026 at 1:40 pm

    I managed to solve the problem.
    It depended on the fact that I had multiple instances of the same form on the same page.

    I implemented hook_forms().

    function mymodule_forms($form_id, $args) {
      $forms = array();
      if(strpos($form_id, 'coverupload_form_') === 0) {
        $forms[$form_id] = array(
          'callback' => 'coverupload_form',
          'callback arguments' => array($args[0], $args[1]),
        );
      }
    
      return $forms;
    }
    

    and then I changed my form call to

    drupal_render(drupal_get_form('coverupload_form_'.$relid, $arg1, $arg2));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a view to list the page content type(title, teaser and image)..
I have created this report using BIRT and phpjavabridge <?php header(Content-type: application/pdf); header(Content-Disposition: inline;
I have created a content type called Event. For each event, I would like
I have a content type Task, where we create task for ourself or user
I have a special content-type that I have created, and one of the fields
I have created a navigation bar with a horizontal unordered list. This displays fine
I've created a views called event which lists all 'event' content type pages, however
I have a childwindow with an associated VM that gets created each time I
I have a content type that references multiple nodes, and I need a way
In SharePoint 2010 BCS, I have created an external content type to retrieve 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.