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 Profiles (Moderator: Dave Greenberg) »
  • Copying address info on form with multiple profiles
Pages: [1]

Author Topic: Copying address info on form with multiple profiles  (Read 928 times)

tso2085

  • I post occasionally
  • **
  • Posts: 75
  • Karma: 0
  • CiviCRM version: 4.7.15
  • CMS version: Joomla 3.6.5
  • MySQL version: 5.5.37
  • PHP version: 5.5.30
Copying address info on form with multiple profiles
September 10, 2012, 07:28:10 pm
I have a membership create form that has onBehalf Organization fields, as well as Individual (primary contact) info that has to be filled out.  It also includes Joomla user registration.  See below for the form content fields.  I also included a screen shot. (in two files due to length of form)

There are three places where the same EMail address needs to be entered.
There are two places for address - which may be the same (Organization, and Primary contact).

I would like to be able to have a checkbox to copy the address if user selects, and copy the EMail address not allowing for changing it in the other required email fields.  This would be somewhat similar to the "Same As Billing" feature in 4.2, but that is only for online billing.  This would just be for membership creation.

I assume I need to add javascript in a tpl file somewhere?   I just need some direction to begin.  When looking at the page source, it is using the "main.tpl" file.


So the form has the following:

Membership Type selection (Intensive, Primary, Base Member) radio buttons
EMail Address    (required by the membership)
______________________

Organization info - Company Name, Address, a few custom fields
______________________

Joomla User Registration  - Username, Password   (user name is always email address, so they have to enter it again)
______________________

Primary contact info - first Name, Last Name, Job Title, Address
EMail Address    (again, seems the "pre-profile" requires the email address also)


I appreciate any help!

Craig

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Copying address info on form with multiple profiles
September 19, 2012, 01:55:30 am
Sounds like a job for jQuery or Javascript and some custom TPL files.

here are some helpful links:


This one has Javascript sample code.  You don't need to use a Drupal module here, but the Javascript is still valid.
http://wiki.civicrm.org/confluence/display/CRMDOC42/Add+%27Same+as+billing+address%27+button+for+convenience
http://forum.civicrm.org/index.php/topic,7719.0.html

Also:
http://wiki.civicrm.org/confluence/display/CRMDOC42/Customize+Built-in,+Profile,+Contribution+and+Event+Registration+Screens

http://civicrm.org/blogs/hershel/how-customize-civicrm-pages-jquery
« Last Edit: September 19, 2012, 06:00:34 am by Stoob »
Try CiviTeacher: the online video tutorial CiviCRM learning library.

Max Hunter

  • I’m new here
  • *
  • Posts: 21
  • Karma: 1
  • CiviCRM version: 4.4.x
  • CMS version: Drupal 7
Re: Copying address info on form with multiple profiles
July 17, 2013, 12:56:25 am
Hi Craig,

I had an organization ask for the same functionality, and I put this code together.  You can drop this into a copy of main.tpl, then put that file in your custom templates directory.  Check it over to make sure it lines up with the fields in your profiles -- if it doesn't, you can enable debugging mode and enter &smartyDebug=1 to the end of the payment page URL to get the correct ID's for your fields.

I'm sure there is a more elegant solution, but this gets the job done!  Thanks to Stoob and Kurund for their guides.

Code: [Select]
  {if $is_for_organization}
  <div id='onBehalfOfOrg' class="crm-section">
    {include file=CRM/Contribute/Form/Contribution/OnBehalfOf.tpl}
<input type="checkbox" id="copyorgAddressLink" value="" onClick="copyAddress(this)">
<label for="copyorgAddressLink">Copy from the organization address.</label>
  </div>
  {/if}

  {* copies over the organization fields if the copyorgaddress box is checked. *}
{literal}
<script type="text/javascript">                                                                                                                                                                                                                                 
function copyAddress(copyorgAddressLink) {
    var orgname = document.getElementById('onbehalf_organization_name').value;
    var phone = document.getElementById('onbehalf_phone-3-1').value;
    var streetAddress = document.getElementById('onbehalf_street_address-3').value;
    var supplementalAddress = document.getElementById('onbehalf_supplemental_address_1-Primary').value;
    var city = document.getElementById('onbehalf_city-3').value;
    var stateProvince = document.getElementById('onbehalf_state_province-3').value;
    var postalCode = document.getElementById('onbehalf_postal_code-3').value;
    var country = document.getElementById('country-5').value;
    var copy_orgname = document.getElementById('current_employer');
    var copy_phone = document.getElementById('phone-Primary-1');
    var copy_streetAddress = document.getElementById('street_address-Primary');
    var copy_supplementalAddress = document.getElementById('supplemental_address_1-Primary');   
    var copy_city = document.getElementById('city-Primary');
    var copy_stateProvince = document.getElementById('state_province-Primary');
    var copy_postalCode = document.getElementById('postal_code-Primary');
    var copy_country = document.getElementById('civicrm_country.name');
 
 
 
    if (copyorgAddressLink.checked) {
       
        if (copy_orgname) copy_orgname.value = orgname;
        if (copy_phone) copy_phone.value = phone;
        if (copy_streetAddress) copy_streetAddress.value = streetAddress;
        if (copy_supplementalAddress) copy_supplementalAddress.value = supplementalAddress;       
        if (copy_city) copy_city.value = city;
        if (copy_stateProvince) copy_stateProvince.value = stateProvince;
        if (copy_postalCode) copy_postalCode.value = postalCode;
        if (copy_country) copy_country.value = country;
    } else {
        if (copy_orgname) copy_orgname.value = "";
        if (copy_phone) copy_phone.value = "";
        if (copy_streetAddress) copy_streetAddress.value = "";
        if (copy_supplementalAddress) copy_supplementalAddress.value = "";       
        if (copy_city) copy_city.value = "";
        if (copy_stateProvince) copy_stateProvince.value = "";
        if (copy_postalCode) copy_postalCode.value = "";
        if (copy_country) copy_country.value = "";
    }
}
 
</script>                                                                                                                                                                                                                                         
{/literal}
« Last Edit: July 17, 2013, 01:25:09 am by Max Hunter »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Copying address info on form with multiple profiles

This forum was archived on 2017-11-26.