When our users create an html snippet for a Profile, it requires a lot of editing to get the references to work. I don't understand why it's written that way.

For reference, here's a snippet of the code for a form that just has first name, last name and email address.

<script type="text/javascript">
var CRM = {"config":{"ajaxPopupsEnabled":true,"isFrontend":""}};
<script type="text/javascript" src="/sites/all/modules/civicrm/packages/jquery/jquery-1.11.1.min.js?r=ogWA8">
<script type="text/javascript" src="/sites/all/modules/civicrm/packages/jquery/jquery-ui/jquery-ui.min.js?r=ogWA8">
<script type="text/javascript" src="/sites/all/modules/civicrm/packages/backbone/lodash.compat.min.js?r=ogWA8">
<script type="text/javascript" src="/sites/all/modules/civicrm/packages/jquery/plugins/jquery.mousewheel.min.js?r=ogWA8">

These snippets are used on different websites than the one where CiviCRM is installed, so the local (non-absolute URL) src="/sites/all/... references don't work correctly.

NOTE: The Help text does indicate that this snippet should work on "ANY website":

Profile HTML Snippet help

  • 1
    Hi mark, Could you edit the question to format the code properly? quite hard to read now – Xavier Apr 15 '15 at 8:22
  • @PTP Mark: Please indent your code so that users can see it. – Joe Murray Apr 18 '15 at 3:22
  • 1
    It is indented - I revised it after Xavier asked that I "format the code properly" But the issues that you and Xavier are having with reading the code is indication of the difficulty that our end users have trying to work with the html snippet. If the experts can't read it, it presents a problem. The specific question I have with it is that all the url references are indirect. I don't see what that has to do with the formatting of the text in this question. – PTP Mark Apr 19 '15 at 17:42

I found this deep in the recesses of Jira: Standalone Form HTML for Profiles has relative URL. So it was fixed back in 3.0 but must have reverted at some point. As best I can follow, Resources.php builds this via addScriptFile, which calls addScriptUrl, which calls getUrl, which creates the URL by running through the extension manager (CRM/Extension/system.php). I'm not sure of the "correct" place to add the base URL and fix this, but I'm guessing it's in the extension manager system file.

  • I think it's a similar issue, but slightly different. I think the form action is correctly absolute at the moment (which the bug fix you reference took care of), but all the javascript declarations are not. – Laryn - CEDC.org Apr 21 '15 at 22:09

we found that if we changed the references from "src="/sites/all/modules/civicrm [...] to a complete url, it would work. An alternative solution seems to be to strip out all references to civicrm and just implement it using a form field.

  • Are you inserting these snippets on a different URL? Why do you need to specify the full URL? Where are you pasting the snippets? – Laryn - CEDC.org Apr 21 '15 at 1:54
  • yes, we are. the profile collects information from a non-civicrm site - the user's web site is often hosted elsewhere. – PTP Mark Apr 21 '15 at 15:33
  • Ah ha. I've never used the Profile HTML Snippet in that way, but the help text does indicate it should be possible. I edited the question to try to make the issue clearer. – Laryn - CEDC.org Apr 21 '15 at 15:47

Check this issue in the bug tracker for some background and possible approaches to resolving this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.