I'm mid-way through my first commercial Drupal site build - an mid-size accommodation booking website - and whilst all has gone relatively well, I have hit a wall regarding Drupal forms. I've searched and experimented for over a day for solutions to this problem, but nothing has made the penny drop for me yet...

Our client wants an online form where visitors can supply a list of names for each room they have booked. Our solution was to provide a form like this:

http://www.dreamscapemedia.com.au/drupal/rooming_list.html

You'll see new fieldsets are added to the form dynamically using good old fashioned javascript. Traditionally I would simply write a PHP form submission handler for this form and be done, however I believe Drupal wants me to work its way by requiring the base form (and all additional fieldsets) be defined using FAPI magic (AHAH/$form mods) - is this correct?

I have a decent amount of PHP coding experience behind me (10 years) but am pretty fresh to Drupal 6. I am on the verge of outsourcing this small bit of functionality as I don't want to spend days on it with no guaranteed solution in sight. Any advice or direction would be greatly appreciated.

Comments

nevets’s picture

I would make it a CCK field by starting with an existing CCK field that had multiple values and supports multiple instances (I believe CCK Address does both).

sydneyshan’s picture

Thanks for your comment, nevets. Are you suggesting I avoid writing my own form and have one built by CCK instead?

I've used the webform module for all other user-input forms on the site (with custom validation and submit code for each form), but have found this quite restrictive (especially the lack of a jQuery date picker).

For some reason I have it in my head CCK should only be used for clients to create content, not for customer/visitors... Is this standard practice to build a form in CCK, then modify the URL to the Add Node screen so it appears like it's in the standard menu hierarchy of the website? I'd then have to override the form submit function for that content type to generate an email to my client rather than adding a node...

Or are you suggesting I should take a CCK field module, create a copy and modify it to my own needs...then create a CCK-based form using it?

nevets’s picture

You can use the webform module or CCK to create forms that collect data from visitors to your website.

Webform has some built in functionality that nodes/CCK does not directly have but can be added with various modules.

On the other hand CCK has a richer set of field types and has ajax and javascript functionality webform lacks and extending webform is more challenging.

One can use the rules module to trigger an email when content is submitted, one can also add custom functionality by implementing a module that implements hook_nodeapi().

One strong suggestion is to let the node be saved as it normally would, it provides a backup to the email and using views you can easily make reports. In cases like this I also point out that Drupal allows you to enrich the handling of the form submissions since you can add tracking fields the submitter does not see but the client can allow for the opportunity for better tracking of the data.

Because it sounds like you need a custom data field that is why I suggest a custom CCK field. Using an existing field as a starting point can speed things up.

sydneyshan’s picture

I have contracted Agileware (www.agileware.net) to accomplish this functionality, and they have suggested the following approach:

1. cck 6.x-3.x-dev - (this is the only way you can have "add another" on a set of fields instead of a field.
2. auto_nodetitle - Node title can be made up of group name and group contact name
3. rules - to send the email notification
4. Custom module required for tokens to print all of 'add another field' fieldsets

I'll try to post the final code here when they're done for others interested in this...

s7ev3n’s picture

I'm in a similar situation

I've been creating fields, but my main problem is that I need a similar functionality as in the Webform's hidden field. I need that when submitting the form some fields are saved to the database but without the client noticing them at all.

Although this topic is really helpful, I could use a small guide "for dummies" on how turn cck module into a form for authenticated users to fill it up like a form.

Thanks in advance guys

richbaldwin’s picture

@sydneyshan

Were you able to get the dynamic field set working?
We just had a discussion today on using this approach on an internal project.

Do you have a demo of it working somewhere or even some code snippets.

At least if you can point us to the cck info/resources you were referred to by agileware.net

Very interested. TIA...

sydneyshan’s picture

Hi richbaldwin,

The dynamic fieldset is working well. We're hoping to launch the site featuring this implementation over the weekend. Check out http://www.newcastleapartments.com.au/guest-information/forms/rooming-list come Monday (26 April 2010) to view the form.

The module that was used was the 'Content Multigroup' - part of CCK 6.x-3.x-dev I believe. The trouble is I can't see this dev version available on the CCK project page anymore.

The Content Multigroup module description states "Combine multiple CCK fields into repeating field collections that work in unison."

When creating the Content Type for this form, it was just a matter of adding a New Group of type 'Multigroup', and then dragging the repeating elements in to this group using the Manage Fields interface.

A Rule (using Rules module) was then created (triggered after saving new content)
The 'condition' was set to 'created content' = 'my form's content type name',
Then two actions were added: 'Send a mail to an arbitrary email address' & 'page redirect'

The email contained tokens (see sample message below), and the page redirect went to a premade 'Thank you' page.

Sample message using tokens:
-----------------------------------------------------------------------------------------
A new rooming list form has been submitted on [node:site-name].

The details of the submission are:
Group name: [node:field_group_name-raw]
Contact person: [node:field_contact_person-raw]
Contact phone: [node:field_contact_phone-raw]

Room information:
[node:group_room_details-raw-titles]

You can view the submission on the website at: [node:site-url]/node/[node:nid]

This is an automated email. Please do not reply.
-----------------------------------------------------------------------------------------

agileware’s picture

Note that the 6.x-3.x-dev version of cck is not displayed on the cck project page.
You have to click the view all releases link or you can get it here - http://drupal.org/node/484068

Agileware are a team of local Drupal developers in Australia, https://agileware.com.au
Agileware support and host Drupal, CiviCRM and WordPress websites.
Contact Agileware today at https://agileware.com.au/contact

sydneyshan’s picture

Agileware had to do some custom work on the CCK module to provide the multigroup field tokens to the Rules email shown above. The mods are found below:

http://drupal.org/node/536260 (patch 5) 'Make "Add more values" button text themeable?'

http://drupal.org/node/156860 (patch 14) 'Support for multiple entry fields and field groups in CCK token'

interestingaftermath’s picture

I cannot get the patch in #14 to work correctly. I know I am doing something wrong. Please help.

I have run the patch and I see the tokens in the list to choose from. I am using Notifications/Messaging to send out node creation emails. All of the tokens work except for the new tokens provided by this patch. They do not print anything in the e-mail.

It's a plain text e-mail and I have tried raw and formatted. I've tried many options in the Tokens/Displays options as well. Here is the latest of my email:

Items:
[group_order-raw-titles]
[group_order-raw]
[field_part_number-formatted-all] | [field_quantity_ordered-raw-all] | [field_description-raw-all]

I have a couple extra fields printing (as you can see) because I would like to see what they do. From that above this is what the e-mail looks like when it hits my inbox:

Items:
| |
What am I missing?
sydneyshan’s picture

It might be best to contact the developer Agileware (www.agileware.net) and purchase an hour or so of support? Unfortunately I didn't work on this solution directly - it was performed by Agileware.

interestingaftermath’s picture

I have figured this out. Any idea how to do something like this?

<p>[field_jb_part_number-raw-0] | [field_quantity_ordered-raw-0] | [field_shipped-raw-0] | [field_description-raw-0]</p>
<p>[field_jb_part_number-raw-1] | [field_quantity_ordered-raw-1] | [field_shipped-raw-1] | [field_description-raw-1]</p>
<p>[field_jb_part_number-raw-2] | [field_quantity_ordered-raw-2] | [field_shipped-raw-2] | [field_description-raw-2]</p>
<p>[field_jb_part_number-raw-3] | [field_quantity_ordered-raw-3] | [field_shipped-raw-3] | [field_description-raw-3]</p>

But instead of those static delta numbers do some sort of a counter? If I do this...

<p>[field_jb_part_number-raw-all] | [field_quantity_ordered-raw-all] | [field_shipped-raw-all] | [field_description-raw-all]</p>

...it does exactly what it says. It prints ALL jb_part_number in a row, then ALL quantity_ordered in a row, etc.

interestingaftermath’s picture

For those that find this thread while doing a search, we are working to resolve this issue over here: http://drupal.org/node/156860

siva_epari’s picture

You can use the flexifield module to get unlimited fieldsets http://drupal.org/project/flexifield

Siva Kumar Epari