Drupal Form API

Being a Drupal newbie with some web experience today I`m struggling with creating a form and using the input from that form to display items on the next page.

Unless I`m mistaken (which given my newbie status is perfectly possible) in a _form_submit you parse your data then return a link to the next page you are displaying.

When inserting and updating a page this works perfeclty because you point back to the page that displays the data you edited . But so far the only thing I found out that takes input from a form and displays it in the next page is by using a multipage form.

This article on Lullabot explains how to create such a page .. but I call that far from simple.
Anyone got a better way to do this .. Al I want to do is have a form where I can select some values, then based on those values get some data from my database and display that. There has to be an easier way than multipage forms. But this Drupal newbie can't find it :(

Next step is to get the above example working ..

Comments

canen's picture

#1 canen : I needed this earlier today

I needed this earlier today and was also stumped that was actually the sane way of doing it. Form API is good for advance stuff but a simple situation like this should have an easier solution.


proxous's picture

#2 proxous : Haha, thanks for posting it.

Haha, thanks for posting it. It's a few hours too late for me, I need this earlier, then found out how. Then going through my RSS reader this just came up.


Kris Buytaert's picture

#3 Kris Buytaert : It works

The Lulabot stuff does indeed work.. But I find it weird you need a hack like this for something that looks like basic functionality to me.


Bart Jansens's picture

#4 Bart Jansens : forms

The example form the lullabot article does work, I have used it before. But there is another way that I recently used as well.

You can set $form['#redirect'] to false and set $form['#after_build'] to some function that adds whatever output you want to generate as an additional form element. Have a look the core comment.module, it uses this method to display comment previews.

You could probably also remove the existing form elements, but in my case showing both the output and the form again was exactly what I wanted.