0

Is it possible in drupal7 to insert a photo in drupal form? I have a start interface that contains two buttons leading to two athors interfaces and I would like to insert a photo above the two buttons. I have tryed the next but it didnt work

function my_module_start_form($form, &$form_state) {
  $image_options = array(
    'path' => 'path/to/img.jpg', 
    'alt' => 'Test alt',
    'title' => 'Test title',
    'width' => '50%',
    'height' => '50%',
    'attributes' => array('class' => 'some-img', 'id' => 'my-img'),
  );


  $image = theme('image', $image_options);

  $form['start']['image'] = array(
    '#markup' => $image,
  );

  $form['start']['next'] = array(
    '#type' => 'submit',
    '#value' => t('Create charts')
  );

  $form['start']['examples'] = array(
    '#type' => 'submit',
    '#value' => t('See charts examples')
  );

  return $form;
}

1 Answer 1

-2

May be this will help..

 function my_module_start_form($form, &$form_state) {
 $image_options = array(
'path' => 'path/to/img.jpg', 
'alt' => 'Test alt',
'title' => 'Test title',
'width' => '50%',
'height' => '50%',
'attributes' => array('class' => 'some-img', 'id' => 'my-img'),
);


 /*$image = theme('image', $image_options);
  $form['start']['image'] = array(
    '#markup' => $image,
  );*/
    print theme_image($image_options);//print the image

    $form['start']['next'] = array(
    '#type' => 'submit',
    '#value' => t('Create charts')
  );
  $form['start']['examples'] = array(
    '#type' => 'submit',
    '#value' => t('See charts examples')
  );
    return $form;
}
4
  • thx both solutions work fine it was my mistake I gave it the wrong path Nov 18, 2013 at 11:38
  • Using print in form definition function is a really bad idea.
    – Mołot
    Nov 18, 2013 at 11:49
  • Hi molot, could you please elaborate me about not to use the print inside the definition of a form, that i can able to understand more.thanks in advance
    – madhurjya
    Nov 18, 2013 at 12:26
  • 2
    Form definition function should only return form array. For display there is a whole theming subsystem. Printing things directly takes them out of form, out of Drupal's renderable structure, and messes with HTML output usually creating invalid HTML. So it's only OK to use it in debug situations, and even then only if needed. Only in .tpl files printing things is perfectly OK.
    – Mołot
    Nov 18, 2013 at 12:46

Your Answer

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

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