Hello

I have been looking all over for how to inject my custom text into a form but I didn't find anything, what I want to do is this:

I have a form let's say

function my_settings($form_state){

which usually has in it the regular form structure

$form['somevar] = array('#type' => 'radios" etc.

but I want to insert at the op of the form page my custom echo of a file list now if I make it and then output the result using an echo before the $form['somevar'] it will display my list in the top right corner of the page instead of just adding it to the form. How can I insert it into the form rectangle so it won't spill out all over the page?

Comments

johnhanley’s picture

Create a theme function that corresponds with the form function name.

function theme_my_settings()
jaypan’s picture

Create a module called mymodule.

In it use this code:

<?php
function mymodule_form_alter(&$form, $form_state, $form_id)
{
  if($form_id == 'my_settings')
  {
    $list = '<p>my list</p>'; // replace this with the actual list you want to output.
    $form['mystuff'] = array
    (
      '#value' => $list;
      '#weight' => -5; // you may need to adjust this to a lighter number to float your list to the top
    );
}
?>

Contact me to contract me for D7 -> D10/11 migrations.

icarusv2x’s picture

I tried with the '#value' => and it worked just fine I didn't even have to use form_alter hook so now I can build my list and also save it since it's part of the form. Thanks again.

jaypan’s picture

Ahh, I didn't realize you had control of the original form definition as well.

Contact me to contract me for D7 -> D10/11 migrations.