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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API custom field with HTML markup
Pages: [1]

Author Topic: API custom field with HTML markup  (Read 696 times)

rulley

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal
  • MySQL version: 5.5.25
  • PHP version: 5.4.4
API custom field with HTML markup
May 27, 2014, 03:11:09 pm
using the API i have a custom field (type note) and am trying to pass in html markup for that field via the API. The opening and closting tags get changed into this &lt; &gt; signs.. I need them to be inserted as is < and > as when i display the field in summary it is writing out the tags. any ideas?
« Last Edit: May 27, 2014, 03:35:54 pm by rulley »

rulley

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal
  • MySQL version: 5.5.25
  • PHP version: 5.4.4
Re: API custom field with HTML markup
May 27, 2014, 04:17:45 pm
found that this guy is doing it in the api.php file --- CRM_Utils_API_HTMLInputCoder::singleton(). Any concerns with commenting this out? and this is the actual piece in the Utils (line 129 $values = str_replace(array('<', '>'), array('&lt;', '&gt;'), $values);

Im just trying to get all of my html passed in as is via the api

rulley

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal
  • MySQL version: 5.5.25
  • PHP version: 5.4.4
Re: API custom field with HTML markup
May 27, 2014, 04:33:14 pm
ok solved... added my custom field after line 109 of CRM/Utils/API/HTMLInputCoder.php (my version 4.4.4)

109   'new', // The 'new' text in word replacements
110   'custom_18', // My custom field - to ignore html encoding

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: API custom field with HTML markup
May 27, 2014, 06:37:31 pm
The HTMLInputCoder isn't exactly beautiful -- ideally, it wouldn't exist. The issue is that at some point (in the prehistorical times of antiquity), someone decided that "first_name", "last_name", and many other (non-HTML) fields should use the "escape-on-input" pattern (where all inputs are escaped and then written to the canonical data-store as escaped-HTML) instead of the more common "escape-on-output" pattern (where the canonical data-store has... pristine data... which must be escaped before being printed to the screen). Escape-on-input is rather weird/unusual for APIs, so we try to hide it when one uses the API (by calling HTMLInputCoder). But it breaks down when the field really is supposed to store HTML content.

Anyway, perhaps it would make sense for us to generalize your work-around: any custom "Note" field should be "skipped" by HTMLInputCoder...

rulley

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal
  • MySQL version: 5.5.25
  • PHP version: 5.4.4
Re: API custom field with HTML markup
May 27, 2014, 09:27:53 pm
sounds good to me...

EranSch

  • I post occasionally
  • **
  • Posts: 40
  • Karma: 3
    • Personal Blog
  • CiviCRM version: 4.5.X
  • CMS version: 4.X
  • MySQL version: 5.5.X
  • PHP version: 5.5.X
Re: API custom field with HTML markup
June 24, 2014, 05:33:01 pm
What about other pre-existing fields (e.g. Notes) -- is there any safe way to create entries containing HTML with the API without modifying the Civi core?

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API custom field with HTML markup

This forum was archived on 2017-11-26.