Hello @salihkulangara ,
This post here should be able to give you more information on doing this: https://www.paidmembershipspro.com/conditional-user-field-member-profile-checkout/
You may have to have a depend array in an array EXAMPLE…
'depends' => array(
array(
'id' => 'how_hear',
'value' => 'Other'
),
array(
'id' => 'how_hear2',
'value' => 'Other2'
),
)
Please let me know if this information is what you are looking for.
KIm W
Thread Starter
Salih K
(@salihkulangara)
@kimwhite Thank you so much.
To make my scenario more clearer, let me give you an example:
In a form I have radio buttons to select ‘Single’ and ‘Couple'(field labelled as Status), If ‘single’ is selected ‘First Name’ and ‘Last Name’ will be shown, and if ‘Couple’ is selected need to show ‘First Name’, ‘Last Name’, ‘Spouse First Name’ and ‘Spouse Last Name'(here First Name and Last Name is common to both status)
In this scenario how can I give condition to First Name and Last Name. If I use below like code it wont work. It check both conditions for true, right? In another words I think not AND but need OR condition.
‘depends’ => array( array( ‘id’ => ‘status’, ‘value’ => ‘Single’ ), array( ‘id’ => ‘Status’, ‘value’ => ‘Couple’ ), )
Also one related question, Is there a way that we can make a radio button selected by default when field is created through User fields section?
Hello,
I don’t know if this is possible with the User Fields GUI. You may be able to access these fields with a custom code like this: I use a checkbox to show the additional spouse fields.
https://gist.github.com/kimwhite/9d5e6b2afbe0e5dc24c0d7ad091ef93b
Kim W
Hey @salihkulangara ,
you need to pass an array for the value to be checked. Try the following:
'depends' => array(
array('id' => 'status', 'value' => array('Single', 'Couple')) )
I faced a similar problem and fixed it using the above mentioned way to achieve an OR-logic with regards the dependancy.
Please let me know if this fixed it for you as well!
Best regards
Daniel
Thread Starter
Salih K
(@salihkulangara)
Hi @danooh thank you for the tip, but unfortunately that does not work for me. I have even tried your tip in Kims code. No luck. FYI, I am using the latest version of PMPRO, and not using Register Helper Addon.
Hi @salihkulangara
I am also using the latest version of PMPRO. Can you provide a snippet of your implementation? Like the whole function that you put into the “pmpro-customizations.php”
On my site I am verifying against multiple conditions (if user picks x or y or z out 10 possible options, then to display a specific custom user field) and it does work.
-
This reply was modified 3 years, 1 month ago by
danooh.
Update @salihkulangara
You may try my solution by changing the type of field ‘Status’ to select.
I will look into multiple conditions on radio fields:
Edit:
I checked the class-pmpro-field.php.
There is a flag implemented to determine whether conditions should be AND’ed or OR’ed (by default ‘depends_or’ is set to false)
Put it like this, adjust values to match yours and it will work with field type ‘radio’
'depends_or' =>true,
'depends' => array(
array('id' => 'status', 'value' => 'single'),
array('id' => 'status', 'value' => 'couple')
)
-
This reply was modified 3 years, 1 month ago by
danooh.
-
This reply was modified 3 years, 1 month ago by
danooh.
Thread Starter
Salih K
(@salihkulangara)
@danooh thank you so much, that worked. Do you see any option that we can add to make a radio button selected by default(I mean adding the ‘checked’ attribute).
@salihkulangara did you add your radio button via custom code?
I did not find ‘checked’-attribute but you can try adding ‘value’ to the array and assign the pre-checked value when creating the user field:
$fields[] = new PMPro_Field(
'status',
'radio',
array(
'label' => 'Status',
'options'=>array('single','couple'),
'value' => 'couple'
)
);
Btw.: I did not test submitting the form.
Thread Starter
Salih K
(@salihkulangara)
@danooh Yes, I had added fields via new user field UI, there is no option for that, So I have to create filed via custom code.
Thank you so much for your help π
-
This reply was modified 3 years, 1 month ago by
Salih K.
Because there have not been any recent updates to this topic, we will be changing the status to resolved. If you have any new questions or if your issue persists, please feel free to create a new topic.