By dropall on
It's my 4th day with Drupal. I've managed to create pages with small PHP snippets without problem.
But when I paste the example in the "Forms API Quickstart Guide", I get nothing.
I suppose there are some more steps not explained in the guide because everybody knows.
Or what else ?
TIA for your help.
Comments
That documentation isn't meant for PHP pages
The Forms API quickstart guide is for developing your own Drupal modules. Don't try to paste the examples into PHP pages as they are guaranteed not to work.
Tip: on your 5th day of Drupal, spend time testing out contributed modules. There is so much to be discovered there that you could keep yourself busy for months. Many of the common problems and tasks that you'll want to get done with Drupal have been solved with contrib modules.
After that, if you're itching to code, read the handbook pages on developing new modules. It's lots of fun =)
- Robert Douglass
-----
My Drupal book: Building Online Communities with Drupal, phpBB and WordPress
I'd be very happy if I could take your advice...
Unfortunately I'm still in a "does it fill my needs" state of mind.
I'd like to do some data entry and publishing. From what I've seen until now, Drupal doesn't seem to be used for this type of application.
I've asked the question in the appropriate section, but no answer.
So I was (naively) trying to explore the forms API.
Do you know a site, module, or whatever which use moderately sophisticated forms to enter data in a database ?
Data entry and publishing?
Yes, Drupal can do that hands down.
My advice, stay away from the forms api completely, as others have suggested also.
That in mind, set up a basic test site. It isn't the 'real' site, because chances are you'll never get it right the first time, so don't take this site too seriously, and start fresh when you're ready.
Next, stick with the basics of simply creating new pages and filling them with content.
Getting fancy, you can format the content. Getting fancier, you can install the wiki-module, so you'll learn how to customize the site, configure drupal, and have a neat way to format and manage the content you plan to publish.
Robert Douglass actually wrote a great book on Drupal that covers everything really well, and in fact there's even a free chapter which covers installing modules. Perfect for you I think.
Don't give up on Drupal, it's a puzzle you'll enjoy once you 'get' the way it all fits in together.
And part of that is this forum and drupal.org. Take your time, and you'll be rewarded.
Have you tried flexinode?
If that isn't enough (and it should be unless your idea of moderately sophisted differs from mine hehe), then you could try creating a new module for your new record type(s). Then you could use the forms API.
You might want to have a look at this stuff to get an idea of what's possible:
http://drupal.org/node/31695
http://buyblue.org
Note: that the forms API is a 4.7 thing and isn't part of 4.6. You had probably figured that out though :)
--
Anton
What version of Drupal? The 4.7 beta?
I forgot to ask, and you may not have thought to check, but the forms API is a programmers tool that is new to 4.7. Please confirm what version of Drupal you're using.
In the 4.6 repository, there was a nice module called Webforms. Flexinode, as mentioned, is also good for data collecting, but it begs the question what you'll be doing with the data after you've collected it, and what form you need it to be in.
If you're on 4.7 already, and are really thinking sophisticated data collection and report building, the combination of the CCK (content construction kit) and the Views module is very interesting. Add to that the Actions and Workflow modules and you'll be catching a glimpse of the Drupal that is about to change the world.
If your needs are specific, and you're a programmer, learning to program custom modules is well worth your while. It is very straightforward, well documented, and is a true rapid development environment that shaves days and weeks off of your programming overhead.
- Robert Douglass
-----
My Drupal book: Building Online Communities with Drupal, phpBB and WordPress
what version
Robert,
I don't use any version yet, but as I know there is a big change in the forms API, I started my tests with the 4.7.
Webforms are too simple for my needs. Flexinode doesn't seem to be the solution neither.
For what I need and what I plan to do with the collected data, see "With this example, it should be clear now" below.
I'm going to have a look at CCK and Actions/Workflow modules.
CCK
When you've played around with CCK for a while you'll probably have some questions. There is more to it than meets the eye (and a lot of work left to be done), so come back and we can discuss it in more depth when you've given it a test drive.
- Robert Douglass
-----
My Drupal book: Building Online Communities with Drupal, phpBB and WordPress
What version of Drupal? The 4.7 beta?
agree
Apache is bandwidth limited, PHP is CPU limited, and MySQL is memory limited.
With this example, it should be clear now
Obviously, my description was not clear enough. So here is an example of what kind of things I'd like to do.
Please take the time to do a search, then look at the returned listing and click on an 'ED' button on the left.
http://www.avtechpulse.com:8080/demo/config/parts/rundbflay
THAT is what I want !
With a little more sophistication :
And of course all this stuff 'themized'.
I must also stress the fact that I'm really interested in the CMS features of Drupal, which are needed too. It's only this problem of forms management that restrains me to embark on your boat.
This is custom development territory
You will need to do some programming to get Drupal to do this (which I suspect you already know). In that case, 4.7 is your clear starting point, and the forms API is your friend. You need to become familiar with the hooks system first, though. Here is a great page to start with:
http://drupaldocs.org/api/head
Don't spend any more time trying to use PHP pages, though. This is a very poor way to extend Drupal in the end. It is much better to learn how to write custom modules.
You'll want to learn how the search system works in Drupal 4.7 (and try the advanced search that lets you specify content types and taxonomy vocabularies). For programmers wishing to use the search features:
http://drupaldocs.org/api/head/group/search
(Drupal 4.7 search, especially with the Porter Stemmer module, is far superior to what you are used to on Drupal.org which is yet to upgrade. It seriously kicks ass.)
As a programmer, I'd encourage you to try Drupal. Depending on the systems you're used to, the architecture might be a bit new and foreign, but well worth becoming familiar with.
Keep asking questions!
- Robert Douglass
-----
My Drupal book: Building Online Communities with Drupal, phpBB and WordPress
back on topic ?
Ok Robert, it feels good to be finally understood.
I've yet to look at CCK, but I think I'm going to investigate the custom modules.
Could you tell me the missing steps to transform the "Quickstart Guide" to a working module ? Just give me the keywords, I'll search the details.
As for the search function, I'm not sure it can help me, as I plan to store my data in a separate database. Correct me if I'm wrong.
TIA
Modules are based on hooks
To make working modules, you need to know what module hooks are available, and what they are for:
http://drupaldocs.org/api/head/group/hooks
The forms API is used any time you want the browser to communicate with the site via POST (this is a simplification of the forms API, but an important starting point). A good starting place for learning the forms API would be to implement a hook_settings for your module. Study existing modules for clues.
The data can be stored wherever. Drupal supports multiple databases seamlessly. Search for database prefixing, and especially the MySQL technique that allows the database name to be used as a prefix: db1.tablename, db2.othertablename.
The search hooks will be interesting to you if you want to do efficient keyword searches on your data. It gives you tools to index, count, rank and weigh words, as well as apply stemming to them (Porter Stemmer module). The workload for doing this is greatly reduced thanks to Drupal's search platform, and will provide far better results than WHERE text like '%search-term%' or other SQL based search techniques. It also supports indexing different sets of data in different domains or realms, so that you can index a set of keywords in one realm using one set of rules, and a different set or a subset of data can be indexed separately with different rules.
That said, you should look at the trip-search module as well and see if there are useful attributes to it for your needs.
http://drupal.org/project/trip_search
- Robert Douglass
-----
My Drupal book: Building Online Communities with Drupal, phpBB and WordPress
And do the tutorial
http://drupal.org/node/17914
- Robert Douglass
-----
My Drupal book: Building Online Communities with Drupal, phpBB and WordPress
Enough for today :-)
Many thanks to you Robert.
Your links gave me what I needed and your search description is exciting.
Now, excuse me, I have to leave : a module tutorial is waiting for me ;-)
Multiple databases
Connecting to multiple databases is possible: there's even a handbook page: http://drupal.org/node/18429. The search hook allows you to index the seperate database as well.
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.
Drupaldocs
Hi dropall,
I agree with Robert: your starting point shouldn't be the forms but the modules. When building modules, you're bound to use forms anyway.
I'm new to Drupal as well and 2 resources have proven extremely helpful:
Good luck.
Vincent
Agreed
Yes Vincent, I'm playing with the node_example module. It's a good starting point.
A very interesting module is 'Views'. It has some holes in the doc, but the author answer questions.
As for the forms, it's now the next step for me. I think I must use the API because AFAIK no module can give me what I need. I even wonder if I can escape the 'one line/one left aligned field' model of the API. I should know more in a few days.
Use the API
Yes, use the API!! ;) I've started to do so myself and I think it's the best way to learn Drupal.
Regarding your question about field customisation, I think you can. By looking at http://drupaldocs.org, it seems that the rendering of each form field is controlled by a combination of 2 functions:
Example: form_textfield() generates something like <input type="text"... />.
(See list of all form functions.)
This function is theme_form_element() and it's the same for every field.
This is where the 'one line/one left aligned field' model that you refer to is implemented.
Vincent
not exactly a form question
In fact, what I want to customize is the surrounding table. I need more than one field on the same line.
drupal_get_form()
OK then drupal_get_form() might be a good starting point.
he's looking at 4.7
the form_textfield function has been removed from 4.7 in favor of the much more robust, much more flexible forms API.
- Robert Douglass
-----
My Drupal book: Building Online Communities with Drupal, phpBB and WordPress
OK
Hi Robert, but what controls the actual (HTML) rendering of a form element then (<input type="text"... />)?
Unfortunately, the Forms API reference only mentions elements, not functions.
The Forms API Quickstart Guide seems to indicate that the form rendering is triggered by drupal_get_form(), which in turn calls form_render(), which in turn calls theme(), which will eventually call something like theme_textfield(). Would that be my answer? ;-)
Sorry if I misled anyone (I found it in the doc for HEAD, though - not 4.6).
Vincent
drupal_get_form()
That is correct... once you've built a form, you trigger its rendering by calling drupal_get_form.
See here:
http://cvs.drupal.org/viewcvs/drupal/drupal/includes/form.inc?view=markup
and look for the theme functions. Here's an example:
So yes, theme('form_element', [...]) is involved... my bad =)
- Robert Douglass
-----
My Drupal book: Building Online Communities with Drupal, phpBB and WordPress
DrupalDoc out of date
Vincent, I looked here:
http://drupaldocs.org/api/head/group/form
and indeed, the docs are out of date. The form_textfield function was in a file caled legacy.inc which was originally thought of as providing backwards compatibility for the older form functions. It was quickly determined that this was simply not possible, and it was removed, but DrupalDocs is still saying that the functions are available. The infrastructure and documentation teams should be notified.
- Robert Douglass
-----
My Drupal book: Building Online Communities with Drupal, phpBB and WordPress
You can theme a form however you want
search for "forms api" and make sure you read the many documents that have been prepared. There are several examples of theming forms in 4.7. One of them is the admin/modules page: each checkbox is a form item, yet it appears without a label inside of a table. If you can do that with the forms API, you can do whatever it is you need, too.
- Robert Douglass
-----
My Drupal book: Building Online Communities with Drupal, phpBB and WordPress
good point
I'm going to see how admin/module does.
Thx
to people reading this thread... :)
Drupal's API documentation has moved to:
api.drupal.org
Anisa.
-----------------------------------------------------------
Kindness builds stronger bonds than necessity.
www.animecards.org - 18,000 card scans and counting!
-----------------------------------------------------------