php 在默认 joomla 3.1.1 注册表单中添加自定义字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17336842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding custom field in default joomla 3.1.1 registration form
提问by dhaval
Recently I have stumbled upon a situation in Joomla 3.1.1where I need to add a custom field attached with default registration form.
最近我在Joomla 3.1.1中偶然发现了一种情况,我需要添加一个附带默认注册表单的自定义字段。
I surfed the existing resources which say that I should navigate to joomla_root/components/com_users/models/forms/registration.xmland then change the file accordingly.
我浏览了现有资源,其中说我应该导航到 joomla_root/components/com_users/models/forms/registration.xml然后相应地更改文件。
I have done that but nothing is showing up. I also need to change registration.php in model and controller too. So, I need your inputs on how to do that. I can't use profile plugin or commercial extensions.
我已经这样做了,但没有任何显示。我还需要更改模型和控制器中的 registration.php 。所以,我需要你的意见如何做到这一点。我不能使用配置文件插件或商业扩展。
One more thing that I've noticed is the fact that changing registration.xml file and such things work perfectly fine in Joomla 2.5 but isn't working in 3.x.
采纳答案by dhaval
Eventually it turns out that the problem was a component called K2.I tried this custom registration stuff in joomla 2.5 and then suddenly thought how about disabling K2 System Plugin..It worked.
最终发现问题是一个名为 K2 的组件。我在 joomla 2.5 中尝试了这个自定义注册的东西,然后突然想到禁用 K2 系统插件如何..它起作用了。
Im posting the steps to do so:
我发布了这样做的步骤:
1.Navigate to joomla_root/components/com_users/models/forms/registration.xml and add a field there.
1.导航到 joomla_root/components/com_users/models/forms/registration.xml 并在那里添加一个字段。
2.Then open up joomla_root/components/com_users/models/registration.php and then in the function register() change ur custom fields.
2.然后打开 joomla_root/components/com_users/models/registration.php 然后在函数 register() 中更改您的自定义字段。
3.Don't forget to add a field in ur database table #_users which you have added in registration.xml
3.不要忘记在你的数据库表#_users中添加一个你在registration.xml中添加的字段
回答by Riccardo Zorn
Joomla ships with a user plugin called "profile" which may contain the fields you want to add already.
Joomla 附带一个名为“profile”的用户插件,其中可能包含您想要添加的字段。
In the administrator go to extensions/plugins, filter by type and choose "user", then find the "Profile" and open it. Check out the options on the right handside, enable the plugin and voila.
在管理员中转到扩展/插件,按类型过滤并选择“用户”,然后找到“配置文件”并打开它。查看右侧的选项,启用插件,瞧。
Warning: most templates override the registration form and they usually don't fire the correct plugin events. If this is the case, your users will only see the "standard" fields in the registration. And if you set any fields as required in the plugin, they will not be registered, but redirected to the complete registration page (the user component), where they will find the fields they already filled in exceptfor the passwords, which can be quite annoying.
警告:大多数模板会覆盖注册表单,它们通常不会触发正确的插件事件。如果是这种情况,您的用户将只能看到注册中的“标准”字段。如果你在插件中设置了任何需要的字段,它们将不会被注册,而是被重定向到完整的注册页面(用户组件),在那里他们会找到他们已经填写的字段,除了密码,这可能相当恼人的。
If the "profile" fields are not sufficient, copy the profile plugin and build your own.
如果“配置文件”字段不够用,请复制配置文件插件并构建您自己的。
Do NOT modify the profile plugin or com_users files like you have done, this is Joomla core and will be overwritten when you next upgrade.
不要像您那样修改配置文件插件或 com_users 文件,这是 Joomla 核心,将在您下次升级时被覆盖。
回答by eglescout
Depending on whether you needed the custom field to be added to the database or not, you could use a form building component such as RSForm!Proor ChronoForms. They both can tie into the user registration system in Joomla and give you a lot of flexibility in custom emails, adding info to database tables, etc. This would insulate you from any core updates that could wipe out your modifications. I believe Chronoforms is free as long as you don't mind a link back to the developers in the form.
根据您是否需要将自定义字段添加到数据库中,您可以使用表单构建组件,例如RSForm!Pro或ChronoForms。它们都可以连接到 Joomla 中的用户注册系统,并在自定义电子邮件、向数据库表中添加信息等方面为您提供很大的灵活性。这将使您免受任何可能消除您的修改的核心更新。我相信 Chronoforms 是免费的,只要您不介意表单中的开发人员链接。
If you can't do that, I would make sure that I had a backup of the files that I modified handy before updating the site. Joomla 3.1.x is a short term build so you have a higher risk of those files getting changed than if you were working on a Joomla 2.5.x site.
如果你不能这样做,我会确保在更新站点之前我有一个我修改过的文件的备份。Joomla 3.1.x 是一个短期版本,因此与在 Joomla 2.5.x 站点上工作相比,这些文件被更改的风险更高。