Describe the issue or problem
The documentation shows how to create a plugin to add custom fields in forms, but I can’t find the registration form id to add custom fields in it.
What application are you using?
For example, OJS 3.4.0.1
Describe the issue or problem
The documentation shows how to create a plugin to add custom fields in forms, but I can’t find the registration form id to add custom fields in it.
What application are you using?
For example, OJS 3.4.0.1
I am not from PKP team, but let me try to help you.
I guess it is the classes/components/form/context/PKPUserAccessForm.php
with FORM_USER_ACCESS
constant.
In lib/pkp/classes/components/form
and classes/components/form
we have all the available Component Forms to use like the tutorial you mentioned. However, it may exists some forms that do not follow this pattern, for example, submission in OJS 3.3.
During development, may be easy to add a Hook like Hook::add('Form::config::before',
and debug/print the $form->id
after loading the page to see which form do you want.
Vc é brasileira?
Sorry, I made a mistake before. The form you are looking is probably:
class PKP\user\form\RegistrationForm extends Form
However, it does not inherits from FormComponent. So, the tutorial you mentioned is useless in this case.
To add custom fields to it you will need to Hook::add
on ::display'
to modify the templates and on ::execute'
to save the values. On OJS 3.4, like:
Hook::add('registrationform::execute', array($this, 'handleRegistrationFormExecute'));
Hook::add('registrationform::display', array($this, 'handleRegistrationFormDisplay'));
function handleRegistrationFormExecute($hookName, $params) {
$form = $params[0];
// ... Look at RegistrationForm to see what you may access
return false;
}
function handleRegistrationFormDisplay($hookName, $args) {
$request = Application::get()->getRequest();
$templateMgr = TemplateManager::getManager($request);
$form =& $args[0];
$templateMgr->assign('newField', defaultOrOldValue);
// Modify the template in formFilter
$templateMgr->registerFilter("output", array($this, 'formFilter'));
return false;
}
Hope it helps! You may look for other plugins that have hooks on ::display
and ::execute
to see better how it works. Also, have a look at #9045 for more details in those differences between Form
and FormComponent
.
Yes, RegistrationForm doesn’t inherits FormComponent, that’s why I couldn’t find the id.
Thank you very much for your explanation!! It brought me some light!
Sim, sou brasileira!
Hello Lívia. eu também sou brasileiro e estou tentando aprender mais sobre esta plataforma. vc pode me ajudar?