简体   繁体   English

Buddypress条件配置文件字段

[英]Buddypress Conditional Profile Fields

Is there any way I can create custom/conditional registration/profile fields in buddypress. 有什么办法可以在buddypress中创建自定义/条件注册/配置文件字段。 I tried Googling a lot about this, but I am not getting proper solution. 我对此进行了很多尝试,但我没有得到适当的解决方案。 The condition what I am thinking of is : 我在想的条件是:

I want to create 2/3 dropdowns, suppose if 1st one contains vehicles type(car, bike,), then the second dropdown's option should change according to what user is choosing in dropdown 1. 我想创建2/3下拉菜单,假设如果第一个下拉菜单包含车辆类型(汽车,自行车等),则第二个下拉菜单的选项应根据用户在下拉菜单1中选择的选项进行更改。

any help would be appreciated. 任何帮助,将不胜感激。 Thanks a ton in advance. 在此先感谢一吨。 :-) :-)

Currently there is no working plugin or hack for that. 目前尚无适用的插件或黑客工具。 I saw such thing on some sites - but this is done via JavaScript and heavily modifying of a registration page source code. 我在某些站点上看到过这种情况-但这是通过JavaScript和大量修改注册页面源代码完成的。

It will be little tricky unless you touch register/resgistration.php source. 除非您触摸register / resgistration.php源代码,否则它不会很棘手。 you can do like this if you little familiar with jquery. 如果您不太熟悉jquery,可以这样做。 Theres a hidden field ( id "signup_profile_field_ids" ) in buddypress registration form which tells server what fields in registration form, it will look like 在buddypress注册表单中有一个隐藏字段(id“ signup_profile_field_ids”),它告诉服务器注册表单中的哪些字段,看起来像

<input type="hidden" name="signup_profile_field_ids" id="signup_profile_field_ids" value="5,11,1,10,32">

value of that field contains field ids of the registration form. 该字段的值包含注册表单的字段ID。

Now, you need to select a parent field to show conditional fields. 现在,您需要选择一个父字段以显示条件字段。 you need to know parent and conditional field ids 您需要知道父域ID和条件域ID

now use this jquery code 现在使用这个jQuery代码

<script type="text/javascript">
  $(function(){
   var childs = new Array("Child id 1","Child id 1"); // your child fields ids
   var options = new Array("Car","Bike"); // your parent field options, notice option and child number is same, which means, one child for one option
   var parent = "Parent Field id"; // place you parent field id
   var currentFields = new Array();
   currentFields = $("#signup_profile_field_ids").val().split(','); // take all current fields ids in an array


   $.each(childs, function(index,value){
     $('#field_'+value).parent().hide(); // hide all child fields first
     currentFields.splice(currentFields.indexOf(value),1);
   });
   $("#signup_profile_field_ids").val( currentFields.join() );
   $('#field_'+parent).after('<div id="conditional-fields-conteiner></div>"');
   $('#field_'+parent).change(function(){
      var option = $(this).val();
      var appendField = childs[options.indexOf(option)];
      var html = $("#field_"+appendField).parent().html();
      $('#conditional-fields-conteiner').html(html);
      $.each(childs, function(index,value){
        currentFields.splice(currentFields.indexOf(value),1);
      });
      currentField[] = appendField;
       $("#signup_profile_field_ids").val( currentFields.join() );
    });
  });
</script>

This may seems complex, but this is the easiest approach. 这似乎很复杂,但这是最简单的方法。 if you are planning it in membership site, dont use it. 如果您打算在会员网站中使用它,请不要使用它。 user can manupulate conditional fields simply by editing html. 用户只需编辑html即可处理条件字段。

Theres also a plugin for this, going to release soon. 还有一个与此相关的插件,即将发布。 I am developing it 我正在开发

http://rimonhabib.com/coming-up-next-buddypress-nested-conditional-fields/ http://rimonhabib.com/coming-up-next-buddypress-nested-conditional-fields/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM