I know I can use '#prefix' to add text above my form but I wanted to know if there are other ways to do this as well.

Comments

Zahor’s picture

Yes, you just create a form field that's of type value.
So something like so:

  $form['fieldname'] = array(
  '#type' => 'value',
  '#value' => "My Value Goes Here",
);
nhero’s picture

I tried this technique but the text isn't showing up.

vijayg’s picture

You can do this by using prefix. Make sure you return the form and cal the form to print.

Jaypan’s picture

The original response had the right idea, except that type 'value' means that the data is never sent to the browser. You can use this:

  $form['fieldname'] = array(
  '#value' => "My Value Goes Here",
);

This is actually 'type' markup, but type 'markup' is the default, so you don't actually need to add that. So the above is shorthand. But if you do want to add a type, you can use this:

  $form['fieldname'] = array(
  '#type' => 'markup',
  '#value' => "My Value Goes Here",
);

But both sets of code will do the exact same thing.

nhero’s picture

thanks, that is exactly what I wanted to do.

amarpanray’s picture

What file is this in and where do I find it? (Sorry I am new)

amarpanray’s picture

Nevermind, found it!