CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • How to correctly update options for selected custom fields in forms / profiles?
Pages: [1]

Author Topic: How to correctly update options for selected custom fields in forms / profiles?  (Read 889 times)

Kampaweb

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
    • Campaignforum
  • CiviCRM version: 3.3.6
  • CMS version: Drupal 6.20
  • MySQL version: 5.1.54
  • PHP version: 5.3
How to correctly update options for selected custom fields in forms / profiles?
June 17, 2011, 02:34:24 am
Hi all!

I'm trying to create several forms that can be used on an external website for newsletter signups.

I use a custom field with a list of 20 newsletters, but I want to display only a selection of them in each form.

Hence, I trimmed the html-snippet of the corresponding profile accordingly, just showing the required fields of the whole range of multiple choice options for each form.

This works fine, with one exception: Whenever the form is submitted, the WHOLE field seems to get updated / reset. I.e. if one of the options that had been removed from the form, has been ticked before, it is unticked now.

Eg. say, the submitter's record has option 1, 2 and 3 ticked and option 4 and 5 unticked.

The form just shows options 1 and 5.

Now, if the submitter ticks just option 5 to ADD this to his selection, the record will ONLY have option 5 ticked after submission (NOT 1,2,3 AND 5 as intended).

Is there any way, to just switch the chosen option, but leave all other options untouched?
We passionately provide NPOs in Switzerland, Germany and Austria with the means to campaign succesfully.

dschafer

  • I post occasionally
  • **
  • Posts: 93
  • Karma: 3
    • Backoffice Thinking
  • CiviCRM version: 3.2.3 - 4.4.4
  • CMS version: Drupal 6.x, 7.x, Wordpress
  • MySQL version: 5.1.x - 5.5.x
  • PHP version: 5.2.x - 5.4.x
Re: How to correctly update options for selected custom fields in forms / profiles?
June 17, 2011, 09:47:13 am
Sounds like you'll need to write a hook to achieve what you describe.

Here is the link to the general description:
http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+hook+specification

You need to use a pre hook on the custom data object.

The hook will be called before the data is written to the database.
In the hook you need to merge the data that is being submitted with the data that is already in the database.

  • Read the content of the existing record
  • Modify the field in the update data as required.

When the hook completes control passes back to civi and the new data will be written to the database.

The primary issue I see is determining how to merge the data.  If item 2 is enabled in the database but not on the incoming record, how do you know if it is because it wasn't displayed vs. the user explicitly unselected it.



Kampaweb

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
    • Campaignforum
  • CiviCRM version: 3.3.6
  • CMS version: Drupal 6.20
  • MySQL version: 5.1.54
  • PHP version: 5.3
Re: How to correctly update options for selected custom fields in forms / profiles?
June 21, 2011, 01:43:48 am
Thanks a lot for your suggestion.

I had hoped there would be a way without hooks (as I am not a coder), but it looks like I'll have to go that road, anyway.
We passionately provide NPOs in Switzerland, Germany and Austria with the means to campaign succesfully.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: How to correctly update options for selected custom fields in forms / profiles?
June 21, 2011, 02:32:57 am
You could also achieve what you need, it appears, using jQuery code. See

http://civicrm.org/blogs/hershel/how-customize-civicrm-pages-jquery

for the basic idea.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Kampaweb

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
    • Campaignforum
  • CiviCRM version: 3.3.6
  • CMS version: Drupal 6.20
  • MySQL version: 5.1.54
  • PHP version: 5.3
Re: How to correctly update options for selected custom fields in forms / profiles?
June 21, 2011, 03:04:46 am
The JQuery approach looks slightly simpler to me, so thanks, for pointing me to that, too!
We passionately provide NPOs in Switzerland, Germany and Austria with the means to campaign succesfully.

dschafer

  • I post occasionally
  • **
  • Posts: 93
  • Karma: 3
    • Backoffice Thinking
  • CiviCRM version: 3.2.3 - 4.4.4
  • CMS version: Drupal 6.x, 7.x, Wordpress
  • MySQL version: 5.1.x - 5.5.x
  • PHP version: 5.2.x - 5.4.x
Re: How to correctly update options for selected custom fields in forms / profiles?
June 21, 2011, 05:13:56 am
Another option you could check is using CSS only.

If you're displaying the list as check boxes each one may have a unique id that you could use to suppress the display.

We've used this technique form hiding custom data on event pages but have not tried it in this specific context

-- Dave

Kampaweb

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
    • Campaignforum
  • CiviCRM version: 3.3.6
  • CMS version: Drupal 6.20
  • MySQL version: 5.1.54
  • PHP version: 5.3
Re: How to correctly update options for selected custom fields in forms / profiles?
June 21, 2011, 05:57:32 am
Suppressing the display of unneeded fields is exactly, what I've tried to do - but only to the avail, that all hidden fields are recorded as "blank" / unticked.
Or did I get something wrong here?
We passionately provide NPOs in Switzerland, Germany and Austria with the means to campaign succesfully.

dschafer

  • I post occasionally
  • **
  • Posts: 93
  • Karma: 3
    • Backoffice Thinking
  • CiviCRM version: 3.2.3 - 4.4.4
  • CMS version: Drupal 6.x, 7.x, Wordpress
  • MySQL version: 5.1.x - 5.5.x
  • PHP version: 5.2.x - 5.4.x
Re: How to correctly update options for selected custom fields in forms / profiles?
June 21, 2011, 07:22:26 am
By editing the html snippet you removed the data that still needs to be rewritten into the data base.

By using CSS instead, you keep all the fields and just visually hide the ones you don't need. The hidden fields cannot be changed so their initial values are preserved.

This will only work if you use a check box presentation - it will not work with any list structure

-- Dave

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • How to correctly update options for selected custom fields in forms / profiles?

This forum was archived on 2017-11-26.