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} {ts}ext.{/ts} {$form.phone.$blockId.phone_ext.html|crmReplace:class:four} {$form.phone.$blockId.location_type_id.html}</td>+ <td>{$form.phone.$blockId.phone.html|crmReplace:class:”phoneUS”} {ts}ext.{/ts} {$form.phone.$blockId.phone_ext.html|crmReplace:class:four} {$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
Drupal Camp Mumbai 2011 – Day 1
Filed in Open Source | Technology Leave a comment
I had an excellent time with fellow drupalars at Drupal Camp Mumbai held at IIT, Powai. It feels great to put faces to irc nicknames and meet the people for real. This always amazes me
.
I was bit late hence missed drupal song ( which I heard was fun ) but reached in time for keynote by Dries Buytaert, original creator and project lead for the Drupal. Dries spoke about early days of drupal and how it has evolved into one of the successful open source project. He also emphasized on having a strong community and then shared his thoughts on drupal’s future.
Jacob Singh’s “How to have an open relationship with software (and still get paid) – Free software in material world“, mainly focussed on how each one of us can benefit by being part of drupal community and in the process grow as a individual/company within drupal community. I really liked his presentation, especially self portraits :)
“Drupal Entities Unleashed – Create your own information architecture with Drupal” by Mukesh Agarwal was a good introduction to entities in drupal. He started with basic concepts and then went on to code level details.
“Drupal, Migrating to Drupal was never so easy“ by Piyuesh Kumar & Dipen Chaudhary demonstrated migration of ROR website into drupal using migrate module. They covered various features of migrate module and it’s integration with drush. It was a great mix of code and actual migration process. This was followed by a good Q& A session.
This kind of summarizes my day at DCM and looking forward for tomorrow’s code sprint. If you guys missed today, don’t miss tomorrow, there are some kool sessions scheduled along with code sprint.
c ya tomorrow
Only if she knew…
Filed in Life etc 3 Comments
He was studying very late last night and felt lazy to get up from his bed. But then just a thought of seeing her beautiful smile forced him out of the bed. He hated early morning lecture and if it was not for her he would have happily bunked and slept through the morning.
He thought, she was the cutest girl in entire class. She was very humble, caring and ever helping nature attracted him. They were good friends, but their friendship was restricted to college hours. He always imagined and practiced several times to ask her out for coffee or dinner, but somehow never dared. He valued their friendship more than anything else and was too scared loose it.
It was the last day of college and juniors had organized sendoff party. This was a good opportunity to express his feelings for her. He planned to ask her for a dance and then propose her. Dance floor was already crowded. His eyes were searching for her in the dim light of dance hall. Finally he found her sitting next to her friend, happily munching chips and sipping coca-cola. She was dressed casually and was wearing blue jeans and white t-shirt. In this low light she resembled like a shinning star and he thought she looked out of the world. Their eyes met each other, and she greeted him with a smile. She could sense something in his eyes. At that very moment he wished to have that smile for rest of his life.
He said, “Would like to dance?”, she said “Yes”. It seems that she was expecting it and now they were on the dance floor. Both of them never danced together, hence it brought some unwanted attention. But both of them were in their own world and acted ignorant. DJ played “Have You Ever Really Loved A Woman”, it was her favorite song and he sensed it’s a right time to convey his feeling. He said, “I think I like you a lot”. Dam!!! what happened, he could not believe what he just said. After practicing million times to say “I love you” in million different ways he managed only this. He was disappointed with himself. There was a silence for few seconds, which made him worried. Just before he could say anything, she responded “I also like you as a friend”. He said “Good”. Then there was a long silence and the song ended. After that incident neither of them discussed it. College ended and both went separate ways.
5 years later…
As usual courtesy great Mumbai traffic, he was late for the movie and his friends were waiting at the entrance. He ran towards the lift and jumped in like a bollywood hero before it closed. He was shocked to see she standing next to him. There was a awkward moment where in he could not understand what to say, shake hands, hug her. She sensed it and held her hand out. He was still recovering and said “hey, nice to see you”. While lift head towards 5th floor, they did normal catching up about work, friends, etc. She had moved recently to Mumbai. They exchanged their numbers and promised to call each other.
That night in the bed he thought about his so called proposal and realized how stupid he was back then. He loved her so much and wondered if he had guts to say “I love you and want to spend his life with her”. He just wished only if she knew how much he loved her.
She was thinking about same incident. She also loved him a lot and but didn’t have enough courage to express her feelings. She thought life would have been so different if and only if she had conveyed what he meant for her. She wished only if he knew how much she loved him.
and her phone started ringing.. she wondered who was calling at this hour, it was him.
setup mac os x (lion) as development machine ( macports: apache + mysql + php + subversion )
Filed in Mac | Open Source | Technology Leave a comment
Here are the instructions to setup Mac OS X ( Lion ) for MAMP software development. Basically you will need apache, mysql, php, subversion and may be phpmyadmin. I am using macports which simplifies the installation process.
1. Install Xcode from apple’s Mac app store. It might take a while because mac app store is very slow/pathetic. ( so don’t blame your ISP )
In this time you can download other useful softwares. My recommendation:
IM: Adium
IRC: Colloguy,
Browser: Firefox (for development), Chrome (Browsing),
Flash Player
Skype
Textmate ( if don’t use vim or emacs )
2. Download macports from http://www.macports.org and follow the installation instructions.
3. Make sure port is updated to latest
sudo port selfupdate
4. Install the packages
sudo port install subversion apache2 mysql5-server php5 +pear +mysql5 php5-xdebug phpmyadmin
Similarly if you need any other software you can install it using macport. ( if it is available on macports )
5. Load ports so that services like apache and mysql start automatically event after restart.
sudo port load apache2
sudo port load mysql5
6. Go to your browser and type http://localhost it should display “It works”. If not then you can manually start apache and mysql.
sudo /opt/local/share/mysql5/mysql/mysql.server start
sudo /opt/local/apache2/bin/httpd -k start
Now you are all set, time to develop some kool stuff
migrate/copy mysql databases from one machine to another
Filed in Mac | Open Source | Technology Leave a comment
I am currently on Mac OS X( Snow leopard ) and have installed mysql using macports. I wanted to copy my databases to another machine Mac OS X ( Lion ) to avoid creating new db’s from fresh. Here are the instructions for the same.
Important: Information about databases is stored in below folder
/opt/local/var/db/mysql5
So basically you need to copy this folder onto your new machine.
1. First backup existing mysql5 folder. ( this is assuming you have already installed mysql using macports )
2. Copy mysql folder to /opt/local/var/db/, for this you need be sudo user.
3. Change owner
chown -R _mysql:_mysql /opt/local/var/db/mysql5
4. Restart your computer ( I didn’t find the better way ) or may be try restarting mysql.
sudo /opt/local/share/mysql5/mysql/mysql.serve
5. When you copy databases, there is a good change that your INNODB engine might not work. So go to mysql terminal and fire
<mysql> show engines;
If it does not show INNODB or is disabled try following:
cd /opt/local/var/db/mysql5
mv ib_logfile0 ib_logfile0.bak
Basically move all ib_logfile* file to .bak files and then restart mysql server. Now go to mysql terminal and do show engines. INNODB should be enabled.
I think this instructions should work fine on any OS as long as you copy databases to correct location.
This saved me few hours and I hope it helps you too
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
MP Trip 2011 ( Gwalior-Orcha-Jhansi-Khajuraho-Bandhavgarh-Jabalpur-Bhopal )
Filed in Adventure Leave a comment
Here are my rough notes that I took during our groups MP trip. Our group was Ruby, Claudy, Junior, Mahesh and me.
Day 0
From Mumbai Dadar: Punjab mail to Gwailor
Day 1
Train was hour late. Reached Gwalior at 5.00pm
Tip: just walk outside and you will find rickshaws charging minimal Rs. 10 per rickshaw to take you to hotel of your choice. At this time of year I would recommend AC room. We got double for Rs. 850 (Hotel Surya). We booked taxi through our Hotel to take us for sound and light show at Gwalior Fort. Taxi charged Rs. 500 ( you might get cheaper deal if you search outside ) other option is to take rickshaw that charges around Rs. 50 to the base of the fort and then you can hire taxi that charge Rs. 200. We had nice dinner at Restaurant Volga. Note that food in general is spicy at this place so be careful before ordering any spicy dish.
Day 2
Inspite of planning to leave early we managed to leave hotel at around 7.00 am. We hired previous day taxi driver to take us around few places in Gwalior. Mainly Sun temple, Gwalior Fort, Sas bahu temple, Teli temple and finally musesum at the palace. In between this we managed to have good breakfast at India coffee house. End of the day driver dropped us at bus stop for our travel to Orcha. There are no direct buses to orcha, so we took bus to Jhansi and then hired auto-rickshaw to take us to Orcha. Rickshaw charged us Rs.150. Our trip to Orcha was very interesting. It was suppose to be super hot, but we experienced dust storm which was followed by rain. I loved getting drenched in rain.
Due to rains there was no current in Orcha but in this darkness we managed to find cheaper and clean accommodation. It for Rs. 450 per room, Hotel Heritage. We reached Orcha around 6.00 pm. We went out for dinner and it was disappointing. I would recommend stick to basic Indian food. Thali is a good option.
Day 3
After speaking to locals and with some research we found which are the important places that we should visit. Main Palace, Jhahangir’s Palace, Ramaraja Temple, another temple next to it ( you can skip that ) and walked to Chatris, which was ok. We finshed all this bit early, so again took rick to Jhansi ( Rs. 120 ) and then we got into bus for Khajuroa. I would stop now since right now I am the bus and can’t see future ![]()
We reached Khajuroa at around 6.30pm. After having tea at the bus stop we hired rickshaw to show us hotel options. We agreed on fare of Rs. 20. We saw few hotels and then finally settled for Hotel Surya. Since we were tired after long journey we wanted bit of luxury and decided to take AC room. Since it is off season we got a good deal. Rs.2200 with extra bedding. We had a decent meal at Hotel Raja Cafe.
Day 4
Again we had a late start. We had already hired local guide for Rs. 350 and same rickshaw person for another Rs. 350 to take us around Khajuraho. Hiring guide helped a lot and he explained very well and showed us lot of Sculptures which we would have not noticed. In between we had breakfast at Madras cafe ( it was ok ) We finished all temples by 2.00pm and then had lunch at Agarwal Restaurant which was next to our hotel. Our first veggie meal which IMO was best meal of the trip. After resting for a while in our cool hotel rooms, we went to see light and sound show at Western temples. Show starts at 7.30pm. IMO it was very good or atleast best sound and light show on this trip. We then had dinner at continental place opposite our hotel. ( Food was ordinary ). After food we checked out of hotel and left for Khajuroa railway station. Our next destination was Bandhavgarh Tiger Reserve ( Tala gate ). This was again long journey, first train to Mahoba, then Mahaba to Katni another train and then Katni to Umaria and then to Tala gate.
Day 5
Khajuroa to Mahoba train journey was just 1 hour, although train time table showed it as 2 hours. Mahoba station was disaster. Total chaos, very dirty but we managed to find place to seat. Adding to misery our connecting train to Katni was further delayed by an hour or so. There were no announcement etc. but somehow we managed to figure out correct platform to board the train. Train came at around 3.00 am. Thank god we had booked AC compartment. We reached Katni at around 10.00 am. We saw our connecting train to Umaria on another platform. So we had to literally run and catch it. We reached Umaria in the afternoon, since we were hungry we decided to eat. Rickshaw charged us Rs. 50 for main market. We had very good veggie lunch in the market. Then we hired rickshaw to take us to Bandhavgarh Tiger Reserve ( Tala ). We were charged Rs. 400. Road is very bad at last 11 km, so I would recommend hiring vehicle which can be 600/ 800 (AC).
We had already arranged our stay at forest rest house. Since there were no safari’s on this day we just relaxed in our room. We had decent dinner at rest house.
Day 6
We got up at 4.15am since we had to leave for morning safari at 5.30am. Safari was good. We saw lot of wildlife except Tiger
We decide to go out for lunch and when to “Al …. something which was decent.
After safari we rested a bit and then went for another safari in the afternoon. Based on our guides recommendation we went to Gate 2 where he thought tiger spotting would be easier. But we didn’t see any tiger nor much wildlife. Due to some confusion we ended up having late dinner. Overall kind of disappointing end to the day.
Day 7
Since we had not spotted tiger, we decided to go very early for our last Safari. We were again disappointed but I was happy with other animals/birds that we spotted. After safari we had to rush for Umaria station, from where we took train for Jabalpur. We hired vehicle ( Rs. 800) for Umaria station. We reached early and again train was 30 min late. Finally our train arrived and as usual our seats were taken by some other passengers. We had to literally fight with them to claim our seats which we had reserved 3 months in advanced. We reached jabalpur at around 3.00pm. We had already booked 11.00pm train to Bhopal. So we decided to check in to a cheap hotel to dump our bags. After that we hired vehicle (Rs. 1000) to take us to Bhedaghat. We took boat ride (Rs. 600 for entire boat). It was interesting and I would recommend it. Then we went to Duadar Waterfalls. Finally we had great dinner at Hotel Clock Towel, chinese restaurant ( highly recommend this restaurant ). Then rented vehicle dropped us to railway station. Train came early at the station and left on time.
Day 8
We reached Bhopal at 6.00am. Again we hired rickshaw (Rs. 10) that showed us few hotels. But at the end we decided to go with Hotel Sonali. It was clean and excellent service. Since it had 24H checkout time, we dropped our bags at the hotel and went for early breakfast. We had excellent Poha at the roadside joint. After we checked in to hotel and informed front desk to arrange a vehicle to take us to Bhimbetka, Sanchi Stupa and Udaigiri ( Rs. 2500 AC vehicle ) We had good veggie lunch at roadside punjabi dabha. For dinner we went out to Hotel Jamil in old bhopal, which was very disappointing.
Day 9
Only highlight was lunch at Bapu ki Kutia. Then we left for Mumbai ( train )
For pics check my previous blog: http://kurund.com/blog/2011/06/29/madhya-pradesh-trip-2011/
Mumbai Meri Jaan: Shameful act at Mumbai domestic airport
Filed in Life etc | Mumbai Leave a comment
Mumbai, what can I say about it. It’s been more than 6 years since I moved to Mumbai. I instantly fell in love with this city. I don’t know what I like about this maximum city, is it loving friends or ever helpful people or excellent public transport or good food ( a self confessed foodie that I am ) or good opportunities for career growth, frankly speaking I really don’t know. But there are few things that I wish were different/change in this wonderful city.
In this post I would like to bring everyone’s attention to the corruption/bribing issues at domestic airport. Besides buses, rickshaw is the most common mode of transport in Mumbai. So it seems like every time a rickshaw that goes to drop passengers at the airport has to pay 10-20 Rs. to traffic police officer at the exit. In fact now a days when you get in the rickshaw for airport, rickshaw driver will ask for meter reading + Rs. 20 extra which he need to give it to the cop. In my opinion this is ridiculous.
So basically at the exit of departure cop will stop the rickshaw and will ask for the license and other details. Eventually he will take 10-20 Rs. and let go rickshaw driver. This has happened to me atleast 2-3 times when I went to drop my friends at the airport. Everyone knows about it and nothing is done to stop it. It seems like now it is part of the system.
I am not sure if there will be any action taken against such corrupt cops/practices. But I just hope someday someone will stop this and make Mumbai even better place to live and to be proud of.