Custom Data Group with multiple records in Contribution Page

Opublikowane
2011-12-19 08:01
Written by
rajesh - member of the CiviCRM community - view blog guidelines

I think there were few discussion in the forum about adding 'Custom Data Group' with multiple records in a profile. We wanted the same for one of our clients, who wanted an Application Form in which they wanted to collect Qualifications and Experience, which obviously is multi-record custom data against contact. As they needed it in a very short period of time, we managed to do a work around to accomplish this. As usual, the wonderful CiviCRM API version 3 and hooks come to the rescue.

 

So the aim was to expose the fields under the multi-record custom group in the contribution page(using buildForm hook) and allow the users to enter multiple rows and save it against the contact(using API).

 

We created a drupal module which does the following

  • Allows admin to set the custom data group, for which the fields can be exposed to the contribution page. View Screenshot
  • Displayed the fields of the custom data group in the contribution page, with the option for the users to add as many rows as they want. View Screenshot
  • Save the entered rows as custom data(multi-record) against the contact.

 

For those who wish to give it a try, you can down the module at

civicrm_customdata_multirow_form.rar

civicrm_customdata_multirow_form.tar.gz

 

Installation instructions 'INSTALL.txt' file is under the module folder.

 

Please note: This module works only for contribution page and not for events.

 

TO DO: Display the multiple records added by the user in the Contribution Confirmation page.

 

 

 

 

 

Filed under

Comments

I did use webforms few times. But didnt play around with it much :)

 

Does webforms support Civi Custom Data Group with multiple records?

Just click the number of records you want, and they will appear.

I don't know if your system uses ajax to add multiple records, but webform_civicrm does not. So if you want to allow up to 9 records, you would need to have all 9 available to the form, and the user would just leave blank any that are unused.

The webform_conditional module can be helpful in hiding unused fields through js to keep things tidy-looking. (and for reasonable numbers of fields, this is preferable to ajax since there's no lag-time).

In the future, I would recommend using webform_civicrm for this sort of task instead of custom code. While it is certainly possible to code any form yourself and feed the results into the api, you are then stuck with the burden of maintaining that code, testing it reguarly or setting up automated tests, and fixing it when it breaks. I learned that the hard way, which is why I wrote webform_civicrm. :)

 

ajax in webform_civicrm?

 

also we should explore the possibility of embedding a webform on a civicrm public page (or any civicrm page). might not be too hard with the various drupal/civi hooks

 

lobo

 

I think ajax in webforms might be hard, since you have to contend with the whole webform module and it's expectations of the form not being ajax.

That said, it may be much easier in D7 than D6.

Embedding a webform on a civi form might be very challenging since webforms are not set up to allow "snippets" to exist within other forms. Probably not impossible though, with some creative use of FAPI and webform's hooks and internal functions.

On the other hand, embedding a civi form on a webform might be quite simple, since you already have the code for that in place for placing profiles on the user/register form, etc.