I'm developing my first extension and I'm looking the way to insert an image in a form.

Can anyone give me suggestions?

Thanks Marcello

  • Can you be more specific? Which form?
    – Coleman
    Mar 6, 2016 at 1:22
  • Hi Colemann, I want to create a Whatsapp extension, passing through the creation of a new SMS provider. It seems to work correcttly, but now I want to add the possibility to send an attached image. So I create a "civicrm_buildForm" hook for the form "CRM_SMS_Form_Upload". No problem to add a file upload button in "Find Mass SMS" form using: $form->add('file', 'attachedfile', ts('..')); and to save the info in the db. But now when editing a previous saved SMS, I want to show the image in the same form (near the button). I'm not able to do this last thing. Thank you for tour interest.
    – Zeno
    Mar 7, 2016 at 17:43
  • Typically this sort of thing is done by assigning a variable to the template e.g. $form->assign('attachedImage', $imageUrl); and then adding markup to the tpl like <img src="{$attachedImage}">
    – Coleman
    Mar 7, 2016 at 19:24
  • Thank's Coleman, it works! The last step I now cannot solve is to put in the $imageUrl the url of the image that is stored in the "Custom Files Directory" in my case <mysite>\drupal\sites\default\files\civicrm\custom Thank's again
    – Zeno
    Mar 11, 2016 at 17:08
  • Typically links like that go via civicrm and do not link to the file directly. See for example how it works when you click on the icon to view an image from a custom field.
    – Coleman
    Mar 11, 2016 at 17:47


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.