有什么方法可以在 buddypress 中创建自定义/条件注册/配置文件字段。我尝试用谷歌搜索很多关于这个,但我没有得到正确的解决方案。我正在考虑的条件是:
我想创建 2/3 下拉列表,假设如果第一个包含车辆类型(汽车、自行车、),那么第二个下拉列表的选项应该根据用户在下拉列表 1 中选择的内容而改变。
任何帮助,将不胜感激。提前致谢。:-)
有什么方法可以在 buddypress 中创建自定义/条件注册/配置文件字段。我尝试用谷歌搜索很多关于这个,但我没有得到正确的解决方案。我正在考虑的条件是:
我想创建 2/3 下拉列表,假设如果第一个包含车辆类型(汽车、自行车、),那么第二个下拉列表的选项应该根据用户在下拉列表 1 中选择的内容而改变。
任何帮助,将不胜感激。提前致谢。:-)
除非您触摸 register/resgistration.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/
目前没有可用的插件或破解。我在一些网站上看到了这样的东西——但这是通过 JavaScript 和大量修改注册页面源代码完成的。