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) »
  • Warning: CRM.url called before initialization
Pages: [1]

Author Topic: Warning: CRM.url called before initialization  (Read 1261 times)

jere

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 1
  • CiviCRM version: 4.3.3
  • CMS version: Drupal 7.22
  • MySQL version: 5.5.31
  • PHP version: 5.3.10
Warning: CRM.url called before initialization
June 12, 2013, 08:46:46 am
I am trying to create a custom profile that interacts with the site using CRM.api. I get the following warning in the Firebug console:

Warning: CRM.url called before initialization

The warning is created in js/rest.js line 46 apparently because CRM.url = function (p, params) { ... } has not been called prior to my api call with p = 'init' and with param initializing the variable tplURL.

After initializing event_id, my api call is
Code: [Select]
CRM.api('Participant', 'get', {'sequential': 1, 'event_id': event_id, 'return': 'contact_id, contact_type, contact_sub_type,display_name,participant_status,participant_register_date'},
        {
          success: function(data) {  ... });

Am I missing an initialization step I should be taking?

Thanks

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Warning: CRM.url called before initialization
June 12, 2013, 09:28:13 am
This initialization happens on all back-end civicrm pages automatically. If you are embedding your profile on the front-end, then you will need to do it yourself. How are you embedding the profile? As an html snippet?
Try asking your question on the new CiviCRM help site.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Warning: CRM.url called before initialization
June 12, 2013, 09:31:34 am
and keep in mind that it will only works from the same domain (site) than the one running civicrm, so you won't be able to paste the html snippet in another site (at least without some custom code)

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

jere

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 1
  • CiviCRM version: 4.3.3
  • CMS version: Drupal 7.22
  • MySQL version: 5.5.31
  • PHP version: 5.3.10
Re: Warning: CRM.url called before initialization
June 12, 2013, 10:05:23 am
I am using a profile I initially created from the menu administer - custom data and screens - profiles.

However, after I copied the Edit.tpl into the CRM/Profile/Form/40 directory I ended up stripping out all the code in the sample and putting all custom code.  I populate much of the page using CRM.api calls based on selections the user makes via input elements provided at the top of the form. For the part of the form that is not using CRM.api, I am using a hook where I add some custom fields using form->assign and elements using form->add(...) and setting defaults using $form->setDefaults. Then using those in the smarty template, I  lay out the page manually.

In the javascript I am adding html fields and their contents using jquery.
I initially had trouble getting the CRM.api to work but it started working after I added
Code: [Select]
<script type="text/javascript" src="{$config->resourceBase}js/rest.js"></script>

at the top of the page.

In the Firebug console I see the data I expected and am adding it to the profile page using jquery and it seems to work fine so far, but am also seeing the warning in the Firebug console that I don't understand.

UPDATE: Everything is on the same domain.
« Last Edit: June 12, 2013, 10:13:54 am by jere »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Warning: CRM.url called before initialization
June 12, 2013, 10:11:31 am
Instead of manually inserting the rest.js I would suggest doing this (from php):
Code: [Select]
civicrm_initialize(); // if you haven't already called that
CRM_Core_Resources::singleton()->addCoreResources();
That ensures that the api has the js needed to run and CRM.url will get initialized.
Note that this means any other Civi js files you (or your form snippet) were including should be stripped out since they will be redundant.
Try asking your question on the new CiviCRM help site.

jere

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 1
  • CiviCRM version: 4.3.3
  • CMS version: Drupal 7.22
  • MySQL version: 5.5.31
  • PHP version: 5.3.10
Re: Warning: CRM.url called before initialization
June 12, 2013, 10:55:50 am
I am only using a hook and the tpl file.  I wonder why it is not being initialized already.

I added this to the top of the tpl file:
Code: [Select]
{php}
  civicrm_initialize();
  CRM_Core_Resources::singleton()->addCoreResources();
{/php}

The warning is gone, so maybe it is resolved.

Thanks for the help.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Warning: CRM.url called before initialization
June 12, 2013, 01:07:43 pm
I think putting php code in your template should be avoided. Better to add it to your hook.
Try asking your question on the new CiviCRM help site.

jere

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 1
  • CiviCRM version: 4.3.3
  • CMS version: Drupal 7.22
  • MySQL version: 5.5.31
  • PHP version: 5.3.10
Re: Warning: CRM.url called before initialization
June 12, 2013, 07:03:05 pm
OK. I will move it. Thanks.

I very much appreciate the help.
« Last Edit: June 12, 2013, 07:12:06 pm by jere »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Warning: CRM.url called before initialization

This forum was archived on 2017-11-26.