0

Form uploads image and if image is uploaded I'd like it to be displayed before the form. What is the right way to do this?

  • What exactly do you mean by "before the form"? If you just want to display the file upload element after the image, you might be better off using CSS instead of overriding elements in PHP. – Aram Boyajyan May 22 '15 at 15:37
  • I don't know how to add something before the form on the page. i.imgur.com/BpxQEQP.jpg – Andy Core May 22 '15 at 16:00
2

You can use hook_form_alter() to add a 'markup' element to the form, with a negative weight so that it floats to the top. For example:

mymodule_form_alter(&$form, &$form_state, $form_id) {

  // Only act on my module's form.
  if ($form_id != 'mymodule_form') {
    return;
  }

  $form['top'] = array(
    '#type' => 'markup',
    '#markup' => 'This will be at the top of the form!',
    '#weight' => -100,
  );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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