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ó
On Dec 18, 2007, at 4:45 PM, Feijó Legendas wrote:
Every site about hook_form, uses node! Can I do that without nodes?
Yes. hook_form() is specific to modules that implement their own node types. You don't want that. What you want is to read the documentation about the Forms API (FAPI) and define your own form builder function, validation routine, submit handler, etc. Then, you can just use hook_menu() to serve up this form at a specific menu location. http://api.drupal.org is your friend. Also, just search in core for hook_menu implementations that use "drupal_get_form" as the menu callback, and you'll find dozens (hundreds?) of examples. Good luck, -Derek (dww)
I'm using drupal_get_form in my hook_menu ! No problem in that part My doubts begin after I filll my forms, how to handle the input data :) If its not the hook_form what I need, I will keep searching end reading FAPI Thanks, Derek BTW, for a personal site, I plan to use CCK and views. But I wanna use Drupal 6 with triggers. So I have to wait CCK folks update that module :) hugs Feijó 2007/12/18, Derek Wright <drupal@dwwright.net>:
On Dec 18, 2007, at 4:45 PM, Feijó Legendas wrote:
Every site about hook_form, uses node! Can I do that without nodes?
Yes. hook_form() is specific to modules that implement their own node types. You don't want that. What you want is to read the documentation about the Forms API (FAPI) and define your own form builder function, validation routine, submit handler, etc. Then, you can just use hook_menu() to serve up this form at a specific menu location.
http://api.drupal.org is your friend.
Also, just search in core for hook_menu implementations that use "drupal_get_form" as the menu callback, and you'll find dozens (hundreds?) of examples.
Good luck, -Derek (dww)
Feijó, It sounds like a fair question. One can start building from scratch, or one can use a framework to leverage reuse. So when you are trying to leverage a framework, you gain only by re-using it, that is, using it. Drupal differs from other CMS's in that it allows the non-programmer to create arbitrary content items (business objects) with arbitrary fields: nodes. The business objects are persisted for you. If you are working with pure CRUD functions in php, then perhaps you should think twice about using a framework, with its huge productivity and trade-offs in favor of non-programming prototyping. But Drupal is so flexible that it does have an answer for you: you can make forms with the FormAPI, set callbacks with hook_menu, even leverage the Drupal validation and submit support, etc. See Chapter 10 of Pro Drupal Development ( http://www.amazon.com/Pro-Drupal-Development-John-VanDyk/dp/1590597559) for some examples. So even though you might feel more at home with something like the Cake framework for what you are describing, you could leverage Drupal forms and persistence and even the upcoming Drupal 6 database schema api ... all without using nodes. Victor Kane http://awebfactory.com.ar On Dec 18, 2007 9:45 PM, Feijó Legendas <patrao@legendas.feijo.info> 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ó
Hi Victor. Thanks for your feedback, We are very confortable with Drupal, we decided to use it about 5 month ago. Several contents will be handled by drupal resources itself, but some others we need much more specific stuff, unavaiable in drupal modules I bought that book!! Arrived last saturday, I already start reading it. Will jump to chapter 10, thanks for the tip regards Feijó 2007/12/18, Victor Kane <victorkane@gmail.com>:
Feijó,
It sounds like a fair question.
One can start building from scratch, or one can use a framework to leverage reuse.
So when you are trying to leverage a framework, you gain only by re-using it, that is, using it.
Drupal differs from other CMS's in that it allows the non-programmer to create arbitrary content items (business objects) with arbitrary fields: nodes. The business objects are persisted for you.
If you are working with pure CRUD functions in php, then perhaps you should think twice about using a framework, with its huge productivity and trade-offs in favor of non-programming prototyping.
But Drupal is so flexible that it does have an answer for you: you can make forms with the FormAPI, set callbacks with hook_menu, even leverage the Drupal validation and submit support, etc. See Chapter 10 of Pro Drupal Development ( http://www.amazon.com/Pro-Drupal-Development-John-VanDyk/dp/1590597559) for some examples.
So even though you might feel more at home with something like the Cake framework for what you are describing, you could leverage Drupal forms and persistence and even the upcoming Drupal 6 database schema api ... all without using nodes.
Victor Kane http://awebfactory.com.ar
On Dec 18, 2007 9:45 PM, Feijó Legendas <patrao@legendas.feijo.info > 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ó
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?
Sure can, the erp module has a erp_contact sub module which uses forms without using nodes. The entries link to nodes, but they are stored in a seperate table, which is not node based. Its 4.7 based, but should be applicable. HTH Simon
I guess.. drupal_get_form launches all the FAPI processes to handle the form. So validate and submit hook should be launched for that form. Also the form is still available by other modules using hook_form_alter.. Just as an example (a quick one) take a look to the contact module (shipped in core). It creates several forms not being related to nodes. On Dec 19, 2007 2:30 AM, Simon Lindsay <simon@iseek.biz> wrote:
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?
Sure can, the erp module has a erp_contact sub module which uses forms without using nodes.
The entries link to nodes, but they are stored in a seperate table, which is not node based.
Its 4.7 based, but should be applicable.
HTH
Simon
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ó
-- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson
What a fantastic reply!! Thanks a lot, Garfield, I successfully set my form to work!! Feijó ----- Original Message ----- From: "Larry Garfield" <larry@garfieldtech.com> To: <development@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ó
-- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson
participants (7)
-
Alessandro Feijó -
Derek Wright -
Feijó Legendas -
Iñaki Lopez -
Larry Garfield -
Simon Lindsay -
Victor Kane