Body: <p>I'm developing my first extension and I'm looking the way to insert an image in a form.</p>
  
  <p>Can anyone give me suggestions?</p>
  
  <p>Thanks
  Marcello</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-06T01:22:02.803Z
Comments.Text: Can you be more specific? Which form?
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-07T17:43:31.723Z
Comments.Text: 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.
Comments.UserDisplayName: Zeno
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-07T19:24:31.153Z
Comments.Text: 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}">`
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-11T17:08:10.217Z
Comments.Text: 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
Comments.UserDisplayName: Zeno
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-11T17:47:57.153Z
Comments.Text: 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.
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-14T11:41:09.693Z
Comments.Text: Thank's again Coleman, I spent all the morning trying to follow your indication unsuccessfully. The custom field creation generate an element for the standard form object and I loose myself in the object complexity.
  Maybe you know what's the object (maybe CRM_Core_Form) and the function where the structures are transformed in html code.
Comments.UserDisplayName: Zeno
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-14T16:50:14.583Z
Comments.Text: You don't need to look at the code, just create a custom field with the GUI, upload an image, and then inspect the link that civicrm creates for viewing the uploaded image - just mimic that format.
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-15T08:03:24.113Z
Comments.Text: Hi again Coleman, maybe I am abusing of your patience but yesterday, I had already looked at the image link.
  The result is like this one : http://127.0.0.1/drupal/civicrm/file?reset=1&id=2&eid=3. I cannot understand the logic of the parameters, changing their values I obtain an error "Could not retrieve the file£
  Thanks again
Comments.UserDisplayName: Zeno
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-15T16:49:47.997Z
Comments.Text: `reset` is a boolean, don't change it. `id` is the file id (look in the `civicrm_file` sql table to see what I'm talking about) and `eid` is short for "entity id" - that's the id of the entity that the file is attached to (activity, or what have you)
Comments.UserDisplayName: Coleman
Tags: <extension><webform-civicrm>
Title: Cicicrm hook buildForm: add image
ThreadText: # Cicicrm hook buildForm: add image
  
  (Asked by: username_0 on 2016-03-03)
  
  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
  
  **Tags:** extension, webform-civicrm
  
  > **Comments:**
  > **username_1**: Can you be more specific? Which form?  
  > **username_0**: 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.  
  > **username_1**: 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}">`  
  > **username_0**: Thank's username_1, 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  
  > **username_1**: 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.  
  > **username_0**: Thank's again username_1, I spent all the morning trying to follow your indication unsuccessfully. The custom field creation generate an element for the standard form object and I loose myself in the object complexity. Maybe you know what's the object (maybe CRM_Core_Form) and the function where the structures are transformed in html code.  
  > **username_1**: You don't need to look at the code, just create a custom field with the GUI, upload an image, and then inspect the link that civicrm creates for viewing the uploaded image - just mimic that format.  
  > **username_0**: Hi again username_1, maybe I am abusing of your patience but yesterday, I had already looked at the image link. The result is like this one : http://127.0.0.1/drupal/civicrm/file?reset=1&id=2&eid=3. I cannot understand the logic of the parameters, changing their values I obtain an error "Could not retrieve the file£ Thanks again  
  > **username_1**: `reset` is a boolean, don't change it. `id` is the file id (look in the `civicrm_file` sql table to see what I'm talking about) and `eid` is short for "entity id" - that's the id of the entity that the file is attached to (activity, or what have you)  
  
  ---
  
  ## 0 answers
  
  