3

I have a wordpress site http://logisticsworkersnetwork.org/

There is a 'profile' sign-up form on the front page. The sign-up form works fine but there is no CSS or theme html when someone makes a mistake on the form. It goes to this page: http://logisticsworkersnetwork.org/?page=CiviCRM&q=civicrm/profile/create&page_id=2 and just shows the error and the form in pure html. That is, it shows the PRINTER-FRIENDLY version of the page. The console error says:

Uncaught ReferenceError: CRM is not defined (anonymous function) @ ?page=CiviCRM&q=civicrm/profile/create&page_id=2:100

NB: I have removed the civiCRM CSS file with Jquery. I also have a few hidden fields which are shown when a validation error occurs. This problem only arose after I switched from my localhost environment to my server (bluehost). I upgraded to civiCRM 4.6.2 (from 4.5.8) when I uploaded the site too.

UPDATE (12/May/2015): I have tried deleting the 'templates_c' folder but it doesn't work. I have tried clearing the cache.

  • Hi, not sure I follow: if you removed the css, it's expected that the form isn't styled anymore, isn't it? – Xavier May 7 '15 at 10:38
  • I just removed the default civiCRM stylesheet. I've added my own styling for the form and validation errors. The problem is that everything (CSS, JS, page elements) disappears when there's a validation error. Does that make sense? If you follow the link and try and submit the form without an email address you'll see what I mean, – thomas jaunism May 7 '15 at 19:44
  • @thomasjaunism to suit StackExchange format, would you consider phrasing this as a question? eg either "Why does this CiviCRM form fail validation?" or "Why does CiviCRM / Wordpress render a validation failure without the Wordpress theme?". SE format requires a question which we can answer, this is more of a descriptive report so it's hard to "answer". – Chris Burgess May 12 '15 at 4:58
  • @Chris Changed to question. – thomas jaunism May 12 '15 at 7:45
  • I think you'll need to debug some more to track this down. There are logfiles which show additional information. CiviCRM's logfile is in public_html/wp-content/plugins/files/civicrm/ConfigAndLog/ on your Bluehost server, and on Bluehost the PHP error log is in your site root eg public_html/error_log. You can SSH in and use tail -f path/to/file.log to watch the logs while you reproduce the error. – Chris Burgess May 12 '15 at 8:10
5

I can't add a comment (doh, stupid reputation requirement) so I'm answering when Thomas Jaunism wrote: "Why would CiviCRM be trying to load the page.php and not the front-page.php that the form is on?"

The Civi plugin loads the WordPress theme's page.php template because many (if not most) themes define a homepage template which does not contain the_content() but rather collections of widgets and archive views. Loading page.php has proved to be the most reliable way to show Civi content on the front end.

If you want Civi to load a different template, there is a filter for this called civicrm_basepage_template. You can therefore load a different template with code such as the following in your functions.php file:

add_filter( 'civicrm_basepage_template', 'use_my_own_template_for_civi' );
function use_my_own_template_for_civi( $template ) {
    if ( some condition is met ) {
        return 'your-template-name.php';
    }
    return $template;
}
  • Thanks. I've tried to change the template but civicrm seems to strip the css from it when it loads with the validation errors. It also replaces 'the_content();' of every page with the form and its validation errors (in printable format). – thomas jaunism May 18 '15 at 21:50
  • If you've got PHP errors (and you have) then you'll need to solve those first before you can address CSS or Javascript issues, as Chris Burgess suggests. – Christian Wach May 19 '15 at 12:27
  • Cheers. I'm still trying to solve those errors. But have hit a bit of wall. Tried reinstalling a new version but there were other errors so am running with this as it has a reasonable amount of functionality. – thomas jaunism May 19 '15 at 12:56
  • 1
    Just to be explicit, for not-so-techies like me, the WordPress theme is not implementing 'page.php' (Just as Christian Wach has explained). Our theme uses 'templates/front-page.php' So we simply need to add the code snippet above to the bottom of your theme's "functions.php" file. The "some condition is met" can be as follows: add_filter( 'civicrm_basepage_template', 'use_my_own_template_for_civi' ); function use_my_own_template_for_civi( $template ) { if ( $template=='page.php' ) { return 'templates/front-page.php'; } return $template; } – Darren Mar 1 '16 at 9:34
  • Darren, there's new template logic in the pipeline. Please have a look at github.com/civicrm/civicrm-wordpress/pull/96 which is less aggressive in its substitution. It will leave the assigned template alone (although this still filterable as per your code) unless it's the homepage, in which case it will try and load 'page.php'. There's a new filter to override this. – Christian Wach Mar 2 '16 at 9:49
3

Viewing the PHP error log revealed a PHP parse error -

[12-May-2015 04:20:05 UTC] PHP Parse error:
  syntax error, unexpected end of file, expecting function (T_FUNCTION) in
  /path/to/CRM/Profile/Form/Edit.php on line 346

We checked that the file in question Edit.php validated, which suggests that perhaps there is a mismatched bracket somewhere else in the site codebase (eg theme files or another plugin).

Recommend -

  • validating files which have been recently modified (php -l *.php)
  • restoring a known good copy of the CiviCRM codebase
  • In fact is has to do with my page.php in the theme directory. Other themes work OK. If I delete the page.php from theme directory it works fine. Why would civiCRM be trying to load the page.php and not the front-page.php that the form is on? – thomas jaunism May 12 '15 at 22:35
  • I'm guessing that's because /?page=CiviCRM to WordPress means you're no longer on the front page when you've submitted the form. You'll need your page template to be valid anyway or the whole site is broken. You can check your PHP is valid using php -l, and you can compare your current template against previous versions and/or the template you based it on to see what's changed (use a file compare tool in your text editor, or diff etc). – Chris Burgess May 12 '15 at 22:45
  • Thanks. Page template works fine throughout the site. The only thing that's changed is civiCRM update to 4.6 and shift to server... – thomas jaunism May 13 '15 at 0:18
  • Your PHP error_log still indicates that you have a misconfigured or incomplete CiviCRM codebase - can't find class CRM_Profile_Page_Router, require_once(CRM/Profile/Form/Edit.php) fails etc. Verify your codebase and follow the upgrade instructions. – Chris Burgess May 13 '15 at 0:23

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.