how to add client side phone validation in CiviCRM

Filed in Open Source | Technology Leave a comment

Recently on CiviCRM irc and forum few people asked about adding client side validation for phone field. By default CiviCRM packages validate plugin, so this can be easily implemented with minor customization. Below is the example of validating US phone number on new contact form.

Index: templates/CRM/Contact/Form/Edit/Phone.tpl
===================================================================
— templates/CRM/Contact/Form/Edit/Phone.tpl   (revision 37399)
+++ templates/CRM/Contact/Form/Edit/Phone.tpl   (working copy)
@@ -39,10 +39,10 @@
     </tr>
 {/if}
 <tr id=”Phone_Block_{$blockId}”>
-    <td>{$form.phone.$blockId.phone.html}&nbsp;&nbsp;{ts}ext.{/ts}&nbsp;{$form.phone.$blockId.phone_ext.html|crmReplace:class:four}&nbsp;&nbsp;&nbsp;{$form.phone.$blockId.location_type_id.html}</td>
+    <td>{$form.phone.$blockId.phone.html|crmReplace:class:”phoneUS”}&nbsp;&nbsp;{ts}ext.{/ts}&nbsp;{$form.phone.$blockId.phone_ext.html|crmReplace:class:four}&nbsp;&nbsp;&nbsp;{$form.phone.$blockId.location_type_id.html}</td>
     <td colspan=”2″>{$form.phone.$blockId.phone_type_id.html}</td>
     <td align=”center” id=”Phone-Primary-html” {if $blockId eq 1}class=”hiddenElement”{/if}>{$form.phone.$blockId.is_primary.1.html}</td>
     {if $blockId gt 1}
        <td><a href=”#” title=”{ts}Delete Phone Block{/ts}” onClick=”removeBlock(‘Phone’,'{$blockId}’); return false;”>{ts}delete{/ts}</a></td>
     {/if}
-</tr>
\ No newline at end of file
+</tr>
Index: packages/jquery/plugins/jquery.civicrm-validate.js
===================================================================
— packages/jquery/plugins/jquery.civicrm-validate.js  (revision 37399)
+++ packages/jquery/plugins/jquery.civicrm-validate.js  (working copy)
@@ -5,4 +5,13 @@
  *  To define phone validation for your site:
  *  jQuery.validator.addMethod(“crm_phone”, function(phone_number, element) { validation logic here }
  */
-
+(function() {
+        jQuery.validator.addMethod(“phoneUS”, function(phone_number, element) {
+            phone_number = phone_number.replace(/\s+/g, “”);
+            return this.optional(element) || phone_number.length > 9 &&
+                phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
+        }, “Please specify a valid phone number”);
+        jQuery.validator.addMethod(“postalcode”, function(postalcode, element) {
+                return this.optional(element) || postalcode.match(/(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXYabceghjklmnpstvxy]{1}\d{1}[A-Za-z]{1} ?\d{1}[A-Za-z]{1}\d{1})$/);
+        }, “Please specify a valid 5 digit zip code.”);
+})();

I have tested this on CiviCRM v3.4 ( latest ). I hope this is helpful.

Originally posted on http://civicrm.org/blogs/kurund/how-implement-client-side-phone-validation

 

, , ,

CiviCRM Code / Book sprint through my camera

Filed in Photography Leave a comment

It’s been amazing code and book sprint in UK, here are some of the moments.

Cross posted from http://civicrm.org/blogs/kurund/civicrm-code-book-sprint-through-my-camera

, ,

jQuery plugin to change the row color on hover

Filed in Open Source | Technology 6 Comments

For my project CivCRM, I wrote a simple jquery plugin to change the row color on mouse hover. It is generic enough and can be used in any project. Here is the implementation.

1. Create a plugin file: jquery.crmrowhighlighter.js

(function($){ $.fn.crmrowhighlighter = function(){

if ($(‘.crm-row-highlighter-processed’).length == 0){

$(‘.selector tr’).hover(function(){

$(this).addClass(‘crm-row-highlight’);

},function(){

$(this).removeClass(‘crm-row-highlight’);

});

$(‘.selector’).addClass(‘crm-row-highlighter-processed’);

};

};

})(jQuery);

2. Create css file: my.css

.crm-row-highlight {

background-color: #FFFFCC !important;

}

Usage:

<script type=”text/javascript” src=”jquery.js”></script>

<script type=”text/javascript” src=”jquery.crmrowhighlighter.js”></script>

<style type=”text/css”>@import url(“my.css”);</style>

<table class=”selector”>

<tr> Row 1: Hover to change the color</tr>

<tr> Row 2: Hover to change the color</tr>

</table>

<script type=”text/javascript”>

$( function(){

$().crmrowhighlighter( );

});

</script>

Note: You need to have table’s class = “selector”

That’s it, now when you hover the row color will change. Hope this helps.

, ,

Integrating IMCE Drupal module with CiviCRM CKEditor

Filed in Open Source | Technology 5 Comments

CiviCRM comes with CKEditor as a default wysiwyg editor. One of the missing feature has been ability to upload /browse existing files on the server using CKEditor. So after some investigation I figured out you can easily integrate IMCE drupal module for this purpose.

Here are the steps:
1. Install IMCE module: http://drupal.org/project/imce
2. Modify packages/ckeditor/config.js

Index: config.js
===================================================================
— config.js (revision 31357)
+++ config.js (working copy)
@@ -9,6 +9,10 @@
// config.language = ‘fr’;
//config.uiColor = ‘#AADC6E’;

+ config.filebrowserBrowseUrl = ‘/index.php?q=imce&app=ckeditor|url@txtUrl|width@txtWidth|height@txtHeight’;
+ config.filebrowserImageBrowseUrl = ‘/index.php?q=imce&app=ckeditor|url@txtUrl|width@txtWidth|height@txtHeight’;
+ config.filebrowserFlashBrowseUrl = ‘/index.php?q=imce&app=ckeditor|url@txtUrl|width@txtWidth|height@txtHeight’;
+
// disable auto spell check
config.scayt_autoStartup = false;

3. Clear you browser cache
4. That’t it, now when you click on image icon you will get option to “Browse Server”, using which you can browse existing file or upload new files on the server.

By default you can browse / upload files only to files directory.

Sorry joomla people.. this will work only for drupal.

, , ,

CiviCRM iphone app ( pre alpha release )

Filed in Open Source | Technology 2 Comments

I have developed very basic iphone app for CiviCRM using Titanium framework.

Features

  • Allows users to “Search Contacts” from their remote CiviCRM database.
  • Add Individuals.
  • App uses CiviCRM REST interface so you can scale it according to your needs.

You can get the code from our public svn repository: http://svn.civicrm.org/tools/branches/v3.2/other/iphone_1.0/

Few screenshots:

Originally posted on http://civicrm.org/blogs/kurund/civicrm-iphone-app-pre-alpha-release

, ,

My notes: Upgrading CiviCRM v2.1 to CiviCRM v3.1 ( Drupal / Joomla )

Filed in Open Source | Technology Leave a comment

Recently we successfully upgraded one of our client CiviCRM install from v2.1 to v3.1.2. Over all I was pretty happy with the CiviCRM upgrade process considering client’s db was in bad shape. This client is one of the early adopters of CiviCRM, ( since v1.8 ) that made things bit worse.

Few things you should remember before starting upgrade:

1. Backup your working CiviCRM database

If you have demo / test server try to upgrade it first rather than live. Always keep backup of your current working CiviCRM database so that you can revert back if needed.

2. Ensure Database Integrity

Never assume client’s database structure is correct, it might be upgraded and hence might be missing foreign key constraints etc, especially if it is been upgraded from CiviCRM v1.x. This might lead to more errors and will take more time to fix / result in more issues during upgrade process.

3. Understand upgrade errors

Try to figure out why you get errors during upgrade process rather than commenting sql or php code in CiviCRM.

4. Fix current database issues

If you get any sql errors during upgrade try to fix your current database. Most of the time database might have stale data.

So based on above, we followed these steps:

1. Backup CiviCRM database. I usually do it via command prompt.( you can also use phpmyadmin or any other database qui’s )

mysqldump -u DBUSER -p PASSWD DBNAME > civicrm_backup.mysql

2. We followed these steps to ensure database integrity before upgrade:

- Export only data from current CiviCRM database. Before exporting I would suggest you should empty cache tables in CiviCRM.

civicrm_cache, civicrm_group_contact_cache, civicrm_acl_cache, civicrm_acl_contact_cache

Then take database backup:

mysqldump5 -c -e -t -n -u DBUSER -p PASSWDS DBNAME > civicrm_only_data.mysql

- Drop current database

mysqladmin -f -u DBUSER -p $PASSWD drop DBNAME

- Create new database and import structure from sql/civicrm.mysql ( from your current install, so in this case creating structure for CiviCRM v2.1 )

mysqladmin -f -u DBUSER -p $PASSWD create DBNAME

mysql -u DBUSER -p PASSWD DBNAME < civicrm.mysql

- Now import data which you exported

mysql -u DBUSER -p PASSWD DBNAME < civicrm_only_data.mysql

After these steps make sure your CiviCRM is working without any errors.

Now you are ready for actual upgrade process :)

1. Upgrade CiviCRM v2.1 to latest 2.2.x release using following instructions:

2. Make sure everything is working fine. If yes than take database backup using instructions mentioned above. ( so that you have db to revert if next upgrade fails )

3. Upgrade CiviCRM v2.2.x to CiviCRM v3.1.x using these instructions:

During this upgrade we got few sql errors:
- We got foreign key contraint failure error when following SQL was fired by CiviCRM

ALTER TABLE `civicrm_activity`

ADD CONSTRAINT `FK_civicrm_activity_source_contact_id` FOREIGN KEY (`source_contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE SET NULL;

We got this error because civicrm_activity table in client’s db had wrong values. For few records “source_contact_id” value didn’t exist in civicrm_contact table. So we did source_contact_id = NULL for those activity records.

- Error

DB Error: constraint violation Database Error Code: Cannot add or update a child row: a foreign key constraint fails (`database_civicrm/civicrm_group_contact_cache`, CONSTRAINT `FK_civicrm_group_contact_cache_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE), 1452

This was because civicrm_group_contact table had entries for contacts that didn’t exits in civicrm_contact table. So we deleted those entries from civicrm_group_contact table.

Note that after each failed step you should rollback to previous working copy / fixed copy.

I agree this process looks bit complicated :) but trust me it might help you to save lot of time in debugging upgrade errors and ensure smooth future upgrade. It took me around 3-4 hours for upgrading this install from CiviCRM v2.1 to CiviCRM v3.1

I hope this helps someone :)

, , ,

iGoogle style dashboard implementation using jQuery

Filed in Open Source | Technology 2 Comments

Today I have finally finished my secret project for CiviCRM v3.1. It was to implement iGoogle style dashboard  with few features specific to our project. Main base for this feature was jquery ui’s sortable, droppable and draggable plugins.

It is always challenging and fun to work on such features. For complete  info check: http://civicrm.org/node/677

, , ,

Few reasons why CiviCRM v3.0 will rock!

Filed in Open Source | Technology Leave a comment

It was very challenging to work on 3.0 feature set and my team worked really hard to ensure release was as per schedule. Now that CiviCRM v3.0 alpha1 is out, I can shed some light on my favorite features in 3.0

Usability

  • Navigation Menu, I bet this will help to reduce number of clicks needed to navigate inside CiviCRM.
  • “Create New” (Shortcuts select) and “Recently Viewed” blocks ( shows recently modified / viewed objects)
  • New work-flow for creating new or selecting existing contact while adding Contribution/ Participant etc.
  • New UI for Contact Edit and Contact Summary which can be highly customized by admin.
  • Eye pleasing look and feel by moving to more neutral color scheme.

CiviEvent

  • New tab interface for Event creation.
  • Waiting list support.
  • Ability to use default / create event templates to simplify event creation procedure.
  • Administrator approval for participants and lot more.

CiviReport

  • 22 default report templates which can be used to create custom Report Instances.
  • Ability to generate tabular/charts for a report, also automatically email reports via cron.

Other Features

  • Multi-site Support: ability to setup single CiviCRM install for multiple sites.
  • Complete migration to jQuery from Dojo ( which helped us to reduce tarball size by 1MB )
  • CiviCase improvements / fixes.

Entire team is super excited about this release, which included  200+ bugs/features and I hope everyone from the community also likes it.

Complete list of features can be found at http://wiki.civicrm.org/confluence/display/CRM/CiviCRM+v3.0

Goa through my Camera..

Filed in Adventure | Goa | Photography Leave a comment

Our team at Web Access, went to Goa for a 4 day trip. It was one of the most memorable trip. Sharing my memories captured on Camera:

Our Itinerary was:

Day 1 : At around 1.30 am started long journey (Mumbai – Goa, we had hired vehicle). Stopped at SinduDurg Fort, Malwan.

Day 2 : Fort Aguada, Calangute (Water Sports), Sapora Fort (DCH spot), Cruise on Mandovi river Panaji ( personally don’t recommend this )

Day 3 : Palolem Beach ( Must see beach in Goa, IMO Best Beach in Goa)

Day 4 : Mangeshi Temple, ShantaDurga Temple – Ponda, Old Goa, Dona Paula ( Dinner at Sea Pebble )

Day 5: At 4.30 am left for Mumbai.

, ,

CiviCRM – Joomla on Shared Hosting

Filed in Open Source | Technology 2 Comments

Usually on Shared Hosting there are lots of restrictions, which makes it impossible to install CiviCRM. Few tricks that i learned over the time that might help others. (Especially if you can’t modify php.ini settings on shared hosting and you don’t know .htaccess) This is sort of customized installation procedure :)

1. Since we have more control on our local install, first install Joomla + CiviCRM on your machine. Make sure that local and live server versions are same. So that there is no conflict when you migrate.  I usually have separate database for CiviCRM, which make it easy for future upgrades and backups.

2. Once you have everything running on local server.

- Take the database backup of CiviCRM db.

- You need export INSERT statements for CiviCRM Component entries from you joomla_components table. Check below INSERT from my install.

- Take the backup of component/com_civicrm and administrator/component/com_civicrm  folders.

3. Now you are all set for migration. Most of the time Shared Hosting allow only ftp access and also there is no untaring/ unzipping utility.  So i would recommend to use a ftp client that resumes upload from the point it gets disconnected. So don’t use gFTP, I always had problems hence started using Filezilla.

- Upload component/com_civicrm and administrator/component/com_civicrm  to respective folder on your server.

- Modify civicrm.settings.php in both compnent/component/ and administrator/component/ make sure fix it according to your server settings.

- now make component entries in your joomla database on live server. If you are on latest CiviCRM 2.1.x and Joomla 1.5.x it should look like:

INSERT INTO `jos_components` ( `name`, `link`, `menuid`, `parent`, `admin_menu_link`, `admin_menu_alt`, `option`, `ordering`, `admin_menu_img`, `iscore`, `params`, `enabled`)
VALUES
( ‘CiviCRM’, ‘option=com_civicrm’, 0, 0, ‘option=com_civicrm’, ‘CiviCRM’, ‘com_civicrm’, 0, ‘js/ThemeOffice/component.png’, 0, ‘task=civicrm/profile\nreset=1\n’, 1),
( ‘CiviCRM Home’, ”, 0, 34, ‘option=com_civicrm&task=civicrm/dashboard&reset=1′, ‘CiviCRM Home’, ‘com_civicrm’, 0, ‘js/ThemeOffice/component.png’, 0, ”, 1),
( ‘Find Contacts’, ”, 0, 34, ‘option=com_civicrm&task=civicrm/contact/search&reset=1′, ‘Find Contacts’, ‘com_civicrm’, 1, ‘js/ThemeOffice/component.png’, 0, ”, 1),
( ‘Manage Groups’, ”, 0, 34, ‘option=com_civicrm&task=civicrm/group&reset=1′, ‘Manage Groups’, ‘com_civicrm’, 2, ‘js/ThemeOffice/component.png’, 0, ”, 1),
( ‘Import Contacts’, ”, 0, 34, ‘option=com_civicrm&task=civicrm/import&reset=1′, ‘Import Contacts’, ‘com_civicrm’, 3, ‘js/ThemeOffice/component.png’, 0, ”, 1),
( ‘CiviContribute’, ”, 0, 34, ‘option=com_civicrm&task=civicrm/contribute&reset=1′, ‘CiviContribute’, ‘com_civicrm’, 4, ‘js/ThemeOffice/component.png’, 0, ”, 1),
( ‘CiviPledge’, ”, 0, 34, ‘option=com_civicrm&task=civicrm/pledge&reset=1′, ‘CiviPledge’, ‘com_civicrm’, 5, ‘js/ThemeOffice/component.png’, 0, ”, 1),
( ‘CiviMember’, ”, 0, 34, ‘option=com_civicrm&task=civicrm/member&reset=1′, ‘CiviMember’, ‘com_civicrm’, 6, ‘js/ThemeOffice/component.png’, 0, ”, 1),
( ‘CiviEvent’, ”, 0, 34, ‘option=com_civicrm&task=civicrm/event&reset=1′, ‘CiviEvent’, ‘com_civicrm’, 7, ‘js/ThemeOffice/component.png’, 0, ”, 1),
( ‘Administer CiviCRM’, ”, 0, 34, ‘option=com_civicrm&task=civicrm/admin&reset=1′, ‘Administer CiviCRM’, ‘com_civicrm’, 8, ‘js/ThemeOffice/component.png’, 0, ”, 1);

Note the 34, is the parent id, so it’s the id of first record. you might have to modify it accordingly.

4. Lastly import CiviCRM database to live server CiviCRM database. Once you import make sure:

- Fire this command in your phpmyadmin or any other sql utitlity on your server for CiviCRM database.

UPDATE civicrm_domain SET config_backend=NULL;

- The login to your Joomla administration section and type this url to reset civicrm menus.

http://<joomla_site>/administrator/index2.php?option=com_civicrm&task=civicrm/menu/rebuild?reset=1

5. Now just logout and login to Joomla. CiviCRM should be working fine.

Few links that might help:

http://wiki.civicrm.org/confluence/display/CRMDOC/Moving+an+Existing+Installation+to+a+New+Server+or+Location

http://wiki.civicrm.org/confluence/display/CRMDOC/Install+2.1+for+Joomla

Note that this is hack to get CiviCRM working with Joomla. For official guide you should check http://wiki.civicrm.org

Hope this helps shared host user…

,

TOP