Home › Forums › General Issues › Conditional logic in register field
Hi,
I’m facing an issue using your plugin. On my register page, there’s no way to make my user fields display dynamically depending on the role select value.
As you can see here :
https://lebonfoot.fr/register/
The ‘Informations joueurs’ should not be displayed if the role (at the end of the form) is not footballeur or footballeuse. But it’s not working
Hi Nicolas,
You can dynamically display fields in your template, based on the value selected in your “Profil” field.
Assuming you’re using a selection field with a single value selectable.
It mays work if you keep the “returned value” setting as “value” and you fill your “choices” setting with value only (not “value : label”).
So you could have something like:
if (get_field('your_selection_field_name') == 'Joueur') {
$condition = true;
}
//Display your selection field first
echo the_field('your_selection_field_name');
//Then, display your conditional fields based on your condition
if ($condition == true;) {
echo $conditional_field_1;
echo $conditional_field_2;
echo $conditional_field_3;
//Etc...
}
Let me know if it helps,
RemSEO
No this is not what I’m talking about.
I’m asking, how in my register form I can display acf field depending on rôle selected on the form.
I can’t edit the rôle selection field because it’s the wordpress one, not a acf field.
I don’t need php solution but ajax or js solution, or acf core solution.
Right here :
https://lebonfoot.fr/register/
while footballeur rôle is not selected, all the ‘informations joueur’ bloc shoul not be displayed.
Moreover, every conditionnal logic between fields are not working, look like acf javascript is not called at all on this page ?
Hi Nicolas,
Normally, you could use acf conditional logic in front end.
Anyway, with this Jquery snippet you could hide/show you fields only when “Joueur” is selected :
$( function(){
//Hide all acf fields targeting their class
$('.acf-user-register-fields').hide();
// Get the value from the selected option in a dropdown and show previously hidded fields
var selectedVal = $( "#wp_rar_user_role option:selected" ).val();
if(selectedVal == 'joueur') {
$('.acf-user-register-fields').show();
}
console.log(selectedVal);
});
Tested and working with jquery 3.x
I’m not sure it’s the best way to do it, but let me know if it helps.
RemSEO
The topic ‘Conditional logic in register field’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.