是否有任何方法可以在buddypress中创建自定义/条件注册/配置文件字段。我试着在谷歌上搜索了很多,但我没有得到适当的解决方案。我想的条件是:
我想创建2/3下拉菜单,假设第一个包含车辆类型(汽车,自行车,),然后第二个下拉菜单的选项应该根据用户在下拉菜单中选择的内容进行更改。
任何帮助将不胜感激。提前非常感谢。: -)
目前没有有效的插件或hack。我在一些网站上看到过这样的事情——但这是通过JavaScript和大量修改注册页面源代码来完成的。
这将有点棘手,除非你触摸register/registration .php源代码。如果您对jquery有点熟悉,也可以这样做。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">
该字段的值包含注册表单的字段id。
现在,您需要选择一个父字段来显示条件字段。你需要知道父字段和条件字段的id
现在使用这个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>
这可能看起来很复杂,但这是最简单的方法。如果你计划在会员网站,不要使用它。用户可以通过编辑html简单地操作条件字段。
还有一个插件,即将发布。我正在开发它
http://rimonhabib.com/coming-up-next-buddypress-nested-conditional-fields/