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) »
  • prevent user from changing membership type
Pages: [1]

Author Topic: prevent user from changing membership type  (Read 983 times)

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
prevent user from changing membership type
November 03, 2011, 11:04:21 am
What's the easiest way of preventing users from changing their membership type when renewing?

We have various membership levels with different fees and want to stop people choosing the wrong (~ie cheaper) membership.  I've been looking to see if I can use hooks to add a 'disabled=disabled' attribute to the select dropdown but can't workout the Quickform syntax for this.  It should be something like this but it appears to be beyond my capabilities.

Code: [Select]
HTML_QuickForm::updateElementAttr (array("price_3"),array("disabled" => "disabled"));
Or maybe there is an easier way to do this?

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
Re: prevent user from changing membership type
November 19, 2011, 10:51:13 am
Eventually got a solution on this but it meant customising the template to accommodate it. Since I'm using pricesets I had to modify the /civicrm/templates/CRM/Price/Form/PriceSet.tpl or at least a copy of it in my custom template directory.

I've used this code to disable the select list so we can still see what level a member is at but they can't change it themselves.

Code: [Select]
{literal}
<script type="text/javascript">
<!--
// Putting these functions directly in template so they are available for standalone forms

window.onload = function() {
        document.getElementById('price_3').disabled = true; ;
    }

</script>
{/literal}

price_3 matches my select box id. You might need to inspect yours to see what it needs to be.

I spent some time playing around with the disabled attribute via CSS before realising it is an HTML attribute.
« Last Edit: November 20, 2011, 11:32:01 pm by speleo »

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
Re: prevent user from changing membership type
November 23, 2011, 12:59:04 pm
Correction - the above didn't actually work as it disabled the selection and therefore the option too. Best bet is to simply remove all the other options from the select box like this:

Code: [Select]

{literal}
<script type="text/javascript">
                var s = document.getElementById('price_3');
var i;
for(i=s.options.length-1;i>=0;i--)
{
if (!s.options[i].selected)
s.remove(i);
}
</script>
{/literal}

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • prevent user from changing membership type

This forum was archived on 2017-11-26.