Is there any up to date information anywhere on the forms API for 5.1? There's loads of stuff about forms scattered around drupal.org, but it all is either dated, contradictory or just plain wrong. I'm having hell of a time working out how all this forms stuff works!

Most searches lead here:

http://api.drupal.org/api/HEAD/file/developer/topics/forms_api.html

but the code on that page described as "a working piece of code" crashes PHP on my machine! Actually, the line at the bottom:

$output = drupal_get_form('test_page', $form);

seems to call the test_page() function recursively, which causes PHP to abort or something. Also, what's that second parameter? The API docs don't describe what it's doing, and the example code doesn't even take a parameter. I can't even see what it's trying to do.

Floundering around by myself, I discovered that this seems closer to a starting point:

function example_form1()
{
  $form['field_2'] = array(
    '#type'          => 'submit',
    'value'         => t('Submit')
  );

  return $form;
}

function testForm()
{
  $content = drupal_get_form('example_form1');
  print theme( 'page', $content );
}

only since I missed the '#' from the '#value' array element, this also causes PHP to bomb out, this time with a memory leak.

It all seems very complicated and rather fragile. I can't find any simple examples in the core code. Short of learning how forms worked in 4.6, then reading up on how they've been converted to 4.7 and then to 5.x, is there anything I can read that will give me simple examples to get started?

Comments

pwolanin’s picture

Well, I suggest posting an issue to the documentation queue- but in the short term, a better bet is to read the 4.7 forms docs, and then the upgrade to 5 instructions. The 4.7 Forms API docs are pretty accurate, but the 5.x are lagging. A good fraction of this 5.x/HEAD page is wrong...

http://api.drupal.org/api/4.7/file/developer/topics/forms_api.html

http://drupal.org/node/64279

Also browse core and contrib module code for ideas.

---
Work: BioRAFT

thrice’s picture

Those suggestions are basically the path I took, but since I'm quite new to Drupal and don't know how forms worked back in 4.[67], learning all that just so I can upgrade the knowledge seemed like a lot of work!

I don't know the Drupal processes and don't know what "posting an issue to the documentation queue" means, but I'll go and figure it out.

Thanks for the pointers.

pwolanin’s picture

it says "Handbook Tools -> issues"

http://drupal.org/project/issues/documentation

---
Work: BioRAFT

pwolanin’s picture

pwolanin’s picture

see: http://drupal.org/node/121138

it may be a few hours before the API site displays the updated file.

---
Work: BioRAFT