investigating multiple image uploads on image form field

blindmime
@blindmime
10 years ago
772 posts
I would like to have an Image upload field on a form take multiple images. (and then I need to display them, of course)

How might I go about this?
updated by @blindmime: 04/14/15 01:29:38AM
paul
@paul
10 years ago
4,335 posts
Is this in a custom module? Set multiple to TRUE if so. From the Gallery module -
    // Gallery Images
    $_tmp = array(
        'name'     => 'gallery_image',
        'label'    => 1,
        'help'     => 5,
        'text'     => 'select images to upload',
        'type'     => 'image',
        'multiple' => true,
        'required' => true
    );
    jrCore_form_field_create($_tmp);



--
Paul Asher - JR Developer and System Import Specialist
blindmime
@blindmime
10 years ago
772 posts
It's an Aparna-generated custom module.
paul
@paul
10 years ago
4,335 posts
It should be straightforward to add the above to its create function.
Change the 'gallery_image' to 'xxx_image' (xxx = your module prefix) and replace the label and help lauguage references to real text strings.


--
Paul Asher - JR Developer and System Import Specialist
blindmime
@blindmime
10 years ago
772 posts
Awesome -- thanks, Paul!
blindmime
@blindmime
10 years ago
772 posts
I have a custom aparna-generated module with an image field create in form designer. I've added the code above to its index.php file and it's allowing multiple images in my custom module, but it doesn't display any images in the update form. In testing, I uploaded multiple images and it works as expected, but no images are displayed upon viewing the update form. I know they uploaded and are in the datastore successfully, because if I go back to original index.php file, the multiple images show in the update form. How do I get the images to display in the update form with the multiple image upload enabled?
douglas
@douglas
10 years ago
2,806 posts
It looks like in the gallery module it uses a template to get the images on the update form.

    $htm = jrCore_parse_template('gallery_update.tpl', $_rt, 'jrGallery');
    jrCore_page_custom($htm, 10);



--

Douglas Hackney
Jamroom Team - Designer/Developer/Support
FAQ-Docs-Help Videos
brian
@brian
10 years ago
10,149 posts
The Gallery module has special needs which is why it uses it's own template - that should not be needed.

The "image" field type knows how to display the previously uploaded images if you are on the update form - but you have to pass in a "values" key in the form create - i.e.

// Form init
$_tmp = array(
    'submit_value' => 'save changes',
    'cancel'       => jrCore_is_profile_referrer(),
    'values'       => $_rt
);
jrCore_form_create($_tmp);

where $_rt is the item detail array - that way the field can "see" the item and show the images that already exist.

Let me know if that helps.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

updated by @brian: 02/28/15 02:32:11PM
blindmime
@blindmime
10 years ago
772 posts
This is in the update section:
    // Form init
    $_tmp = array(
        'submit_value' => 9,
        'cancel'       => jrCore_is_profile_referrer(),
        'values'       => $_rt
    );
    jrCore_form_create($_tmp);

If I add this to the update section, one photo is displayed:
// Task Photo
    $_tmp = array(
        'name'     => 'task_photo',
        'label'    => 1,
        'help'     => 5,
        'text'     => 'select photos to upload',
        'type'     => 'image',
        'multiple' => true,
        'required' => false,
	 'value'    => true
       
    );
    jrCore_form_field_create($_tmp);

If I don't add that at all, multiple photos are displayed (but I don't get the multiple upload function). Apparently, the form designer image field can already display multiple images. Evidently my module code above is missing something it needs to do that?
updated by @blindmime: 02/28/15 04:24:29PM
brian
@brian
10 years ago
10,149 posts
Try changing the "value" on the image form field create to:

'value' => $_rt

Let me know if that helps.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
blindmime
@blindmime
10 years ago
772 posts
No photos are displayed if I change it 'value'.
brian
@brian
10 years ago
10,149 posts
I just checked out the merchandise store module which supports multiple images per item, and I'm not seeing any issues - there really should not be anything you need to do. I do see that "value" is being set to false:

    // Product Images
    $_tmp = array(
        'name'     => 'product_image',
        'label'    => 25,
        'help'     => 26,
        'text'     => 27,
        'type'     => 'image',
        'value'    => false,
        'multiple' => true,
        'required' => false
    );
    jrCore_form_field_create($_tmp);

So you might try that.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
blindmime
@blindmime
10 years ago
772 posts
With 'value' => false no images are displayed. If I take that line out, only one image is displayed. If I don't reference this field at all in the update section, then it does display multiple photos, but I can't upload multiple photos.
updated by @blindmime: 03/06/15 01:07:21AM
brian
@brian
10 years ago
10,149 posts
blindmime:
With 'value' => false no images are displayed. If I take that line out, only one image is displayed. If I don't reference this field at all in the update section, then it does display multiple photos, but I can't upload multiple photos.

Something is not right - can you ZIP up your module and send it to me?

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
blindmime
@blindmime
10 years ago
772 posts
No doubt it's something I'm doing. I'll send over the module.

Tags