[SOLVED] JavaScript to activate/deactivate a plan in the registration form

8 years 1 month ago - 8 years 1 month ago #278908 by sarah963
Hi

I am working to find a way so that during registration, the user can not choose a plan if he/she are from certain country. So, I thought of this scenario:

1-create a field and call it "country_check". This field is 'code' field-type.
2- put a code in the parameter section that return 1 if the country selected by the user is included in the list and 0 if otherwise.
3- inside the plan's workflow: use 'Conditions on CB Fields to show plan at registration' and set the condition that the value of the field "country_check" is equal to 1 in order to show the plan.

So, checking the right country and showing the plan all have to occur before the user hit the 'sign up' button.. so, I need javascript for this. I think the 'code' field type only takes PHP, right?

Can I put a javascript code inside the parameter of the 'code' field ?? If not, where? And where Should I put the .js file if needed?

My original thought was activate/deactivate plans on registration form instead of show/hide them, but I guess I can do that with javascript had I know where to put the code!

Here is the php code I thought of initially that would check for countries before I realized that I need a javascript not PHP:
There is maybe some syntax errors in the below code, I just want you to get the idea..
switch ($user->cb_country) {
case "Afghanistan":
case "Angola":
case "Bangladesh":
case "Benin":
case "Bhutan":
case "Burkina Faso":
case "Burundi":
case "Cambodia":
case "Central African Republic":
case "Chad":
case "Comoros":
case "Congo, Democratic Republic of the":
case "Djibouti":
case "Equatorial Guinea":
case "Eritrea":
case "Ethiopia":
case "Gambia, The":
case "Guinea":
case "Guinea-Bissau":
case "Haiti":
case "Kiribati":
case "Lao Peoples Democratic Republic":
case "Lesotho":
case "Liberia":
case "Madagascar":
case "Malawi":
case "Mali":
case "Mauritania":
case "Mozambique":
case "Myanmar":
case "Nepal":
case "Niger":
case "Rwanda":
case "Samoa":
case "Sao Tome and Principe":
case "Senegal":
case "Sierra Leone":
case "Solomon Islands":
case "Somalia":
case "Sudan":
case "Timor-Leste":
case "Togo":
case "Tuvalu":
case "Uganda":
case "Tanzania, United Republic of":
case "Vanuatu":
case "Yemen":
case "Zambia":
    return 1;
    break;
default:
    return 0;
}

Thanks Alot
:)

Please Log in to join the conversation.

8 years 1 month ago #278949 by krileon
Edit your plan and under the Workflows tab apply a "Dynamic Conditions on other plans and CB Fields to show this plan and to allow subscribing to it" condition to your plan based off your country field. This will show/hide the plans as needed based off your condition. No need for any custom coding to do this. If you need to match multiple values you can do this with REGEXP. Example as follows.

And following CB Field: cb_country
Condition: Matches regexp below
Value: /Afghanistan|Angola|Bangladesh/

Note this is REGEXP and your strings need to be escaped as needed if you've quotes or anything of the sort in the value to match against.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

8 years 1 month ago #278961 by sarah963
Thanks Kyle

Unfortunately, I can not fit all the exempt countries in the 'Value'
It just takes up to the country called 'Kiribati'

I also tried it with few countries but it's not working.
The plan is hidden but choosing one of those countries does not show it!!

:(

Please Log in to join the conversation.

8 years 1 month ago - 8 years 1 month ago #278967 by krileon

Unfortunately, I can not fit all the exempt countries in the 'Value'
It just takes up to the country called 'Kiribati'

Looks like it's due to reg_conds_value_1 database table column in _cbsubs_plans being varchar(255) instead of text. So you can only supply up to 255 characters.

I also tried it with few countries but it's not working.
The plan is hidden but choosing one of those countries does not show it!!

Are you sure the values you're conditioning against are the actual values for the field and not the labels? Example as follows.

Value: usa
Label: United States of America

In the above you need to condition against usa.

Not sure what more to suggest. This is the only way to condition plans at this time. If values are used and are short 3 country character codes it may all fit.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: sarah963

Please Log in to join the conversation.

8 years 1 month ago #278973 by sarah963
Thank goodness, cb_country value is set by: country_id and label: country_name

So, my regex is:
/4|10|25|30|36|250|40|42|57|43|52|46|63|71|73|75|88|102|199|105|134|270|148|144|151|158|161|166|172|29|182|176|209|264|238|215|218|32|221|224|271|237|242|246|245|177|267|268/


So, I used countries ids not names and that helped with the problem of the varchar(255) and now everything is working ,,

Thank you so much Kyle, I appreciate your excellent support.. :) :)
I am done with the website, you won't hear from me for a long time now, and less headache for you. lol
The following user(s) said Thank You: krileon

Please Log in to join the conversation.

8 years 1 month ago #278994 by krileon

I am done with the website, you won't hear from me for a long time now, and less headache for you. lol

lol, never a headache. Am glad to help! :)


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: nant, sarah963

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.479 seconds

Facebook Twitter LinkedIn