[development] Implementing without nodes (Alessandro Feij?)

Larry Garfield larry at garfieldtech.com
Thu Dec 20 22:27:48 UTC 2007


Nifty, thanks Peter.  I made a few whitespace cleanups to it just now (it still had a few hard wordwraps in it.)

--Larry Garfield

On Thu, 20 Dec 2007 14:07:05 -0500, "Peter Wolanin" <pwolanin at gmail.com> wrote:
> FYI, I just cut-n-pasted (with a little editing) Larry's forms intro
> into a handbook page in the module-developer's section:
> http://drupal.org/node/202756
> 
> Hopefully having a page here will make it easier for new devs to get
> started with the Forms API.
> 
> -Peter
> 
>>
>> ---------- Forwarded message ----------
>> From: Alessandro Feijó <patrao at legendas.feijo.info>
>> To: <development at drupal.org>
>> Date: Wed, 19 Dec 2007 11:11:30 -0200
>> Subject: Re: [development] Implementing without nodes
>> What a fantastic reply!! Thanks a lot, Garfield,
>>
>> I successfully set my form to work!!
>>
>>
>> Feijó
>>
>>
>> ----- Original Message -----
>> From: "Larry Garfield" <larry at garfieldtech.com>
>> To: <development at drupal.org>
>> Sent: Wednesday, December 19, 2007 12:01 AM
>> Subject: Re: [development] Implementing without nodes
>>
>>
>> If you want a form that is detached from the node concept, you just
> define
>> the
>> form itself and call it from the menu handler directly.  You can use
>> hook_forms() for it, but don't have to.  The form itself gets submitted
> as
>> normal, and you have complete control over it.
>>
>> A bare skeleton might look like this:
>>
>> function example_menu($may_cache) {
>>   $items = array();
>>
>>   if ($may_cache) {
>>     $items[] = array(
>>       'path' => 'example',
>>       'callback' => 'drupal_get_form',
>>       'callback arguments' => array('example_form'),
>>   }
>>
>>   return $items;
>> }
>>
>> function example_form() {
>>   // define your $form here, reading from the DB as needed.
>> }
>>
>> function example_form_validate($form_id, $form_values) {
>>   // Do stuff with $form_values here and set errors if needed.
>> }
>>
>> function example_form_submit($form_id, $form_values) {
>>   // Do stuff with $form_values here and call DB queries if needed.
>> }
>>
>> Now going to /example will display the form defined by example_form(),
> and
>> when it's submitted it will first be validated by example_form_values()
> and,
>> it passes, will get passed to example_form_submit() for whatever saving
> you
>> want to do.
>>
>> For more information, see:
>> http://api.drupal.org/api/file/forms_api.html/6
>> http://api.drupal.org/api/file/forms_api_reference.html/6
>>
>> You can, of course, get ridiculously more complicated than that
> (especially
>> when you start working with custom theming of forms, which is all sorts
> of
>> exciting), but that should get you started.
>>
>> Cheers!
>>
>> On Tuesday 18 December 2007, Feijó Legendas wrote:
>> > I'm trying to figure out how to implement several modules, that do not
> use
>> > nodes at all
>> >
>> > I need to set lots of forms, this forms are used to edit, insert or
> search
>> > my tables
>> >
>> > I'm having dificulty controling the data flow of my forms.  What hooks
> I
>> > use? I try hook_form, but any code I set there isnt executed.
>> >
>> > Every site about hook_form, uses node! Can I do that without nodes?
>> >
>> >
>> > TIA
>> >
>> > Feijó
>>



More information about the development mailing list