2

A Form having a form element of term reference with checkboxes widget. I want to insert a image tag with each taxonomy term name,

For example here is the html of taxonomy term reference

< div class="form-item form-type-checkbox form-item-field-user-interest-und-24"> < input type="checkbox" id="edit-field-user-interest-und-24" name="field_user_interest[und][24]" value="24" checked="checked" class="form-checkbox ajax-processed"> < label class="option like-taxonomy-term" for="edit-field-user-interest-und-24">-uejo < /label> < /div>

so how can i insert image tag inside div tag so that its html become this

< div class="form-item form-type-checkbox form-item-field-user-interest-und-24"> < input type="checkbox" id="edit-field-user-interest-und-24" name="field_user_interest[und][24]" value="24" checked="checked" class="form-checkbox ajax-processed"> < label class="option like-taxonomy-term" for="edit-field-user-interest-und-24">-uejo < /label> < img src="image=path" alt="image-text"> < /div>

2 Answers 2

4

You should be able to add a prefix or suffix with the field. See Field Suffix in the Form API, So your code might be:

$form['copy'] = array(
'#type' =>'checkbox', 
'#title' => t('my taxonomy term.'),
'#field_suffix' => '<img src="myimg.png" />',
);

You can use field_prefix if you want it to come before.

0

I believe that the best option would be to use a custom module to perform a hook_form_alter() and add the image programmatically to the form array.

There are no exiting contrib modules that I am aware of that will do this for you, seeing as it is a very specific need that requires an individualized solution.

2
  • How i write my code in form alter so that image tag would be show as sibling with input and label tag.
    – Akash Jain
    Jul 9, 2014 at 20:51
  • The Form API provides for additional fields which you can put the image into. Two examples are #field_suffix and #field_prefix.
    – coreyp_1
    Jul 9, 2014 at 23:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.