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 CiviMember (Moderator: Deepak Srivastava) »
  • How to customize a few things on Contribution Forms
Pages: 1 [2]

Author Topic: How to customize a few things on Contribution Forms  (Read 3147 times)

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 customize a few things on Contribution Forms
December 29, 2010, 09:40:08 am
No you can't put Javascript code into a CSS file. CSS files are for CSS code.

Javascript must go into a .js file. Or inline.

As far as running on every page, it's actually safe, meaning it won't generate an error whether or not the item in question is found. Note that the actually text after the # should be the id of the HTML object in question.

To make it run only on certain pages you can either do that via targeting the body id of your page, if that's unique for each page, or by only including this JS file on the relevant pages, via PHP code. But this is a bit more complicated. First thing is to just get it working at all--as noted, it can run on every page and it won't break anything.

 
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.

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Re: How to customize a few things on Contribution Forms
December 29, 2010, 10:00:13 am
Oh cool hershel, it actually works!

The page loads, and a second later I see the jQuery do its thing and the correct radio button is selected.

Acceptable duct-tape for now. Thank you, thank you, thank you!!!  ;D
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

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 customize a few things on Contribution Forms
December 29, 2010, 10:04:21 am
It works? Fantastic. :)

Duct tape? Much better than white-out on your screen anyhow. ;)

Glad to help.
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.

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Re: How to customize a few things on Contribution Forms
December 29, 2010, 11:17:54 am
"Duct tape" in the sense that now business logic is within our custom theme and NOT in a .php file. I am just having a very hard time understanding the positive value for putting business logic code in the theme. I also have a hard time getting my mind around business logic that is defined in the data rather than .php files on the server. Both in my mind are not the places to go searching to track down a business logic bug.

Anyway, we need to get this site LIVE, then we can work on refinements. Pre-Selecting the correct radio button is going to prevent many support contacts!!! Thank you again!!
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

torrance123

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 3
  • CiviCRM version: 4.0
  • CMS version: Drupal 7
  • MySQL version: 5.0.91
  • PHP version: 5.3.3
Re: How to customize a few things on Contribution Forms
August 21, 2011, 09:13:45 pm
We had an issue where we had a recurring contribution form and we wanted to set the default to "I want to contribute this every XX months" and then hide the "I want to make a one time contribution" option.

In Drupal this would be a simple hook_form_alter (possibly adding your own vlidation function too). In Civi, I created my own wee module and used hook_civicrm_buildForm to edit the form as such:

Code: [Select]
function civicrm_form_alter_civicrm_buildForm($formName, &$form) {
 if ($form->_id == 2) {
    $form->setDefaults(array('is_recur' => 1));
    unset($form->_elements[$form->_elementIndex['is_recur']]->_elements[0]);
  }
}}

This works, but right off the bat the things wrong with this are:

  • Accessing private properties directly (eg. $form->_elements)
  • Modifying private properties directly which is much worse (ie. unset($form....))
  • That this leaves a single option with a radio toggle still attached.

Still, despite these issues, I'm not sure how else we could change these. Quickform wasn't giving me the methods I needed to make the changes I wanted.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How to customize a few things on Contribution Forms
August 21, 2011, 10:51:22 pm

Would doing this via a jquery snippet be a lot easier?

Basically seems like it might be a lot easier and cleaner in this case (u hide a div for one, and set the value for the is_recur)

In the php code, u could also freeze the element, so users cannot modify it.

Yes, QF does not have nice public functions to manipulate stuff (i.e. is not very hook friendly)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

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 customize a few things on Contribution Forms
August 22, 2011, 03:14:32 am
Quote from: Donald Lobo on August 21, 2011, 10:51:22 pm
Would doing this via a jquery snippet be a lot easier?

I would think so. torrance123, see:

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

for ideas.
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.

torrance123

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 3
  • CiviCRM version: 4.0
  • CMS version: Drupal 7
  • MySQL version: 5.0.91
  • PHP version: 5.3.3
Re: How to customize a few things on Contribution Forms
August 22, 2011, 03:37:57 pm
No doubt it would be easier, but a big part of me feels very uneasy using javascript (or css) for anything other than page behaviour (which must degrade gracefully for those without javascript). I would only feel right about doing something like form modification on the server, not on the client, and only in the appropriate places in the server code too, or else modifications to core civi will result in spaghetti code.

Drupal's form api (and related form hooks) handles this really well, and allows for modules to radically change the form, its validation rules, and the manipulation of incoming data. I know a change to QF is on the the cards, and I'd like to throw my money behind further investigation of Drupal's fapi as a replacement.

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 customize a few things on Contribution Forms
August 23, 2011, 03:33:51 am
Quote from: torrance123 on August 22, 2011, 03:37:57 pm
No doubt it would be easier, but a big part of me feels very uneasy using javascript (or css) for anything other than page behaviour (which must degrade gracefully for those without javascript).

This is true in many cases, but not for CiviCRM. Without Javascript, a user will not be able to use CiviCRM. Virtually at all actually. It depends on Javascript for some of its most basic functions.
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.

torrance123

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 3
  • CiviCRM version: 4.0
  • CMS version: Drupal 7
  • MySQL version: 5.0.91
  • PHP version: 5.3.3
Re: How to customize a few things on Contribution Forms
August 23, 2011, 03:30:11 pm
Quote
Without Javascript, a user will not be able to use CiviCRM.

For the backend administration of civi, it certainly appears to rely on a lot of js. But for, eg., front end contribution forms? These appear to work just fine without js (to not do so would be bug, imo). Therefore, modifications must also work without requiring js, surely.

Pages: 1 [2]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • How to customize a few things on Contribution Forms

This forum was archived on 2017-11-26.