By janekD7 on
I would like to make custom form with image field, but there is no image type in
http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7
so instead i use managed_file type but it doesn't give an image preview. My question is how to get image preview like this from core Image field?
My code looks like this:
<?php
$element['type_image'] = array(
'#title' => t('Image'),
'#type' => 'managed_file',
'#default_value' => variable_get('type_image', ''),
'#upload_location' => 'public://multipurpose_field_images/',
);
?>
Comments
have you a solution ?
Hi janekD7,
Please have you a solution about your bugs, i have the same problem...
Thanks in advance,
DHM.
I make a question in
I make a question in stackexchange you can follow this link
A solution
Finally I found a solution somewhere on the Internet but forgot to post it here. So now I can only try to remember how is it working (it's now a part of working module, so it works for sure).
NOTE: multifield is the name of the module
For sure it's not copy/paste code but I think it can help somehow if you encounter similar problem.
Works, but remove button goes missing
Your code worked great with the theme function. (I added "return $output" in theme_image_multifield_multitype for it to show up).
However, when using the theme function, the remove button goes off. I am presuming that the image form element is getting replaced with the return value of the theme function.
When the theme function is not used to show the image thumbnail, the form element gives the link to the upload image file and replaces the upload_button with remove_button.
Any ideas on how we can show the remove button after the thumbnail has been rendered?
Fixed, remove button is now showing up
To show the remove button, renamed $base to $output and moved it inside the condition:
Hello, The only thing is
Hello,
The only thing is that if you mix '#theme' with '#state', the field is always shown...
If I remove the '#theme' line the states works again...
I can't find why? Any ideas?
And Thanks for the code.
David THOMAS
http://www.smol.org
Awesome Code!
This code is awesome... I have used it & it has created a preview form uploaded image.
Thanks Dude!
Varun Kr Pandey
Can I use java script to crop original image ?
Hey can you tell me that how can I use java script in this form to crop the image at uploading time..while showing its preview in the widget form?
Actually I want to do a field image with crop option at the time of loading the image or at view of image so that it can be useful
Varun Kr Pandey
Reverce
How i can implement reverse goal?
I want to add imageField to my content type and preserve all its functionality as max size, auto resizing etc. but get rid all that magic with ajax uploading, showing thumbnail and also surrounding fieldset in addition form. So i want to have plain (classic) "select file" fields in addition form but remain all internal D7 logic.
What does that have to do
What does that have to do with showing an image preview in the form API (the topic of this thread)?
Contact me to contract me for D7 -> D10/11 migrations.
That about not showing an
That about not showing an image preview in the form API.
I believe i need to use form_alter but i'm unable to do that on my own. Also i can't find answer to my question in documentation so idecided to ask may question in related conversation. Is i doing it wrong?
The default is that an image
The default is that an image preview isn't shown. Your question is about removing Ajax functionality - a different topic altogether.
Contact me to contract me for D7 -> D10/11 migrations.
owlcarousel display for hook theme_file_widget_multiple
I want help for owlcarousel display for hook theme_file_widget_multiple in file upload preview for drupal 7 with help of owlcarousel module.
Not work for me in custom form
Hi,
I am trying the above threads for generating an image field in custom form. But it is not showing any thumbnail when we upload the file. I have checked the theme function and it is getting fid as 0. Please help me to get it working.
Thanks
see my comment here
see my comment here https://www.drupal.org/node/1041684#comment-11403959
For D8 see http:/
For D8 see http://stackoverflow.com/questions/34100546/drupal-8-add-an-image-field-...