Easy JQuery Modificaiton of CiviCRM Forms

Have you ever wanted to modify a CiviCRM contribution or event registration page?  Taken a look at those Smarty templates?  Doesn't look pretty does it.

In the article I describe how to easily add JQuery/javascript to any form you want and modify the page.

First, and hardest of all, is create a basic CiviCRM extension.  There is a program that will generate a basic extension that integrates with CiviCRM but doesn't yet add functionality.

Create an Extension

Visit the CiviCRM wiki page for how to create a base Module Extension. http://wiki.civicrm.org/confluence/display/CRMDOC43/Create+a+Module+Extension

Once you have created your extension you need to implement one CiviCRM hook to add your javascript file to the page of your choice.

I created an extension called com.skvare.testextend. The main php file to edit in this case is testextend.php.

CiviCRM hooks that you implement will start with the last part of the name: testextend

The function below implements hook_civicrmbuildForm.  Notice the call to the function addScriptFile. This code will add the javascript file my_alter_contribform.js to any contribution page with an id of 2. The 'com.skvare.testextend' is the name of the extension I created.

function tctaextend_civicrm_buildForm($formName, &$form) {
if($formName=='CRM_Contribute_Form_Contribution_Main'){
	 if($form->_id==2 ){
	  CRM_Core_Resources::singleton()->addScriptFile('com.skvare.testextend', 'my_alter_contribform.js');
	 }
}

Thats all it takes to be able to add javascript/jquery modifications to a CiviCRM form.

Here's an example of the javascript file with some simple modifications. Put your javascript file in the base directory of the extension, the same place where you see [youmodulename].php. In my case it was the directory with testextend in it.

This function changes the default text for the 'Other Amount' text field when you enable contributions on a contribution form. It also changes the text of the "Conbribute" button based on the membership section fieldset. The value for this fieldset label is set on the settings page for the contribution as the 'Title - New Membership' and 'Title - Renewals' fields on the Memberships tab. So if the user if getting a membership for the first time the button says "Join Now!". If the user is returning to the form to renew their membership the button says "Renew Now!" File my_alter_contribform.js:

/**
 * This is our closure - all of our code goes inside it
 *
 * This style of closure is provided by jquery and automatically
 * waits for document.ready. It also provides us with a local
 * alias of jQuery as $.
 *
 * ES5 specifies that the first line inside our closure
 * should be 'use strict';
 */
/*jslint indent: 2 */
/*global CRM, cj, ts */
 
cj(function ($) {
  'use strict';
  // Variables declared here will be globally available within this closure

	//Change Other amount text box label
	$('.other_amount-section label').text("Other donation amount (optional)");
	
		//Change Contribute button text to Join or Renew
	//for New Active Membership version of page
	if($('.membership-group #priceset legend').text()=="New Active Membership") {
	 $('#_qf_Main_upload-bottom').attr('value', 'Join now!');
	
	}
	// for Renew Active Membership version of page
	if($('.membership-group #priceset legend').text()=="Renewing Active Membership") {
	 $('#_qf_Main_upload-bottom').attr('value', 'Renew now!');
	
	}
		
	}

});//end cj

Use your JQuery magical powers to your hearts content without having to mess with Smarty templates!

Tags: 

Comments

Membantu pasar properti

Membantu pasar properti mungkin secara politis sulit tetapi tidak melakukannya, mengingat potensinya untuk menghasilkan pekerjaan dengan cepat, akan menjadi kesempatan besar terjawab. Sistem properti saat ini disfungsional. Anda tidak dapat mengayunkan tongkat sihir dan menciptakan solusi instan Tren Jilbab Terbaru serta cipto junaedy dan cipto junaedy tetapi ada langkah signifikan yang, jika termasuk dalam rencana fiskal yang akan datang Anda, akan membantu memindahkan industri ke arah kontribusi dinormalisasi untuk GNP. Kepastian, kepercayaan dan kredit - ini adalah bahan utama

Though I have not tried to

Though I have not tried to modify CiviCRM forms ever but it was really interesting to know how to make it using JQuery. I know the use of JQuery and how to do the stuffs with it but this modification is something new for me. Thanks for sharing about it and writing the codes for it. Keep updating. http://www.geektek.com/

Download Mp3

<a rel="dofollow" title="King Lagu" href="http://kinglagu.wapka.me">King Lagu</a> - <a rel="dofollow" title="Kumpulan Lagu MP3 Terbaru" href="http://berkaslagump3.wapka.mobi/music/list/">Kumpulan Lagu MP3 Terbaru</a> dengan tampilan oke dan responsive. <a rel="dofollow" title="Situs Lagu MP3 Terbaru" href="http://situslagu.yu.tl">Situs Lagu MP3 Terbaru</a> ini memiliki Lagu (MP3) yang sangat banyak. Tak heran banyak yang <a rel="dofollow" title="Download Lagu MP3" href="http://alfine.heck.in">Download Lagu MP3</a> disini. Tunggu apalagi, download MP3 kesukaanmu di <a rel="dofollow" title="STAFA" href="http://segan.site">STAFABand MP3 Downloads</a>

sembelit

a morning visit to a progress, successful greetings

<a href="http://obatnya.info/obat-tradisional-sembelit-ampuh-mujarab/">Obat Tradisional Sembelit</a>
<a href="http://pengobatansecaraalami.com/obat-sembelit-cair-alami-terbaik/">Obat Sembelit Cair QnC Jelly Gamat</a>
<a href="http://obatnya.info/obat-herbal-sakit-pinggang-ampuh/">Obat Tradisional Sakit Pinggang</a>
<a href="http://www.jneherbal.com/obat-herbal-cair-sakit-pinggang-sebelah-kanan-m... Sakit Pinggang Cair QnC Jelly Gamat</a>

Cara Mengobati Kanker Rahim dengan Sarang Semut

<a href="http://tokoherbaltasik.com/penyebab-sakit-telinga-pada-ibu-hamil/">Penyebab Sakit Telinga pada Ibu Hamil</a><a href="http://obatinfeksirahim.tipssehatonline.web.id/cara-alami-mengobati-kank... Alami Mengobati Kanker Rahim dengan Sarang Semut</a><a href="http://www.pengobatanhipertensi.info/olahraga-untuk-mengatasi-hipertensi... untuk Mengatasi Hipertensi pada Ibu Hamil</a><a href="http://obatlukapayudara.com/usia-rentan-terkena-kanker-payudara/">Usia Rentan Terkena Kanker Payudara</a><a href="http://jianxincapsule.com/cara-alami-mengobati-jantung-bengkak-pasca-mel... Alami Mengobati Jantung Bengkak Pasca Melahirkan</a>

test

Bronkitis adalah infeksi pada saluran pernapasan utama dari paru-paru atau bronkus yang menyebabkan terjadinya peradangan atau inflamasi pada saluran tersebut. Kondisi ini termasuk sebagai salah satu penyakit pernapasan. obat bronkitis anak

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.