Add new field to registration form

hi dears
i want to add some field to registration form
i add each of my need to this address lib/pkp/templates/frontend/components/registrationForm.tpl

for example

	<div class="Sex">
			<span class="label">
				{translate key=""}
				<span class="required">*</span>
				<span class="pkp_screen_reader">
					{translate key="common.required"}
			<select name="Sex" id="Sex" required>
			    <option value="0">{translate key=""}</option>
			    <option value="1">{translate key=""}</option>

and add this code to lib/pkp/classes/user/form/

	function execute($request) {
	$requireValidation = Config::getVar('email', 'require_validation');
	$userDao = DAORegistry::getDAO('UserDAO');

	// New user
	$user = $userDao->newDataObject();


	// Set the base user fields (name, etc.)
	$user->setAffiliation($this->getData('affiliation'), null); // Localized

	$user->setInlineHelp(1); // default new users to having inline help visible.

	if (isset($this->defaultAuth)) {
		// FIXME Check result and handle failures
	$user->setPassword(Validation::encryptCredentials($this->getData('username'), $this->getData('password')));

	if ($requireValidation) {
		// The account should be created in a disabled
		// state.
		$user->setDisabledReason(__('user.login.accountNotValidated', array('email' => $this->getData('email'))));


	$userId = $user->getId();
	if (!$userId) {
		return false;

	// Associate the new user with the existing session
	$sessionManager = SessionManager::getManager();
	$session = $sessionManager->getUserSession();
	$session->setSessionVar('username', $user->getUsername());

	// Save the roles
	$userFormHelper = new UserFormHelper();
	$userFormHelper->saveRoleContent($this, $user);

	// Insert the user interests
	$interestManager = new InterestManager();
	$interestManager->setInterestsForUser($user, $this->getData('interests'));

	if ($requireValidation) {
		// Create an access key
		$accessKeyManager = new AccessKeyManager();
		$accessKey = $accessKeyManager->createKey('RegisterContext', $user->getId(), null, Config::getVar('email', 'validation_timeout'));

		// Send email validation request to user
		$mail = new MailTemplate('USER_VALIDATE');
		$this->_setMailFrom($request, $mail);
		$context = $request->getContext();
			'userFullName' => $user->getFullName(),
			'activateUrl' => $request->url($context->getPath(), 'user', 'activateUser', array($this->getData('username'), $accessKey))
		$mail->addRecipient($user->getEmail(), $user->getFullName());
	return $userId;

but when i clicked on submit button , see white page

in additional i add these property to db , on user table
can you help me?


Hi @amirhosein

I think you do not need to add that property to the DB table users - it could be saved in the DB table user_settings. For that you would need to add it also in the UsersDAO function getAdditionalFieldNames ( In that case you would set the user metadata in the RegistrationForm something like this: $user->setData('sex', $this->getData('Sex'));
Else, if you want to use the new DB column, you would also need to add the getSex and setSex to the classes/users/ bzw. class and also consider it everywhere in the i.e. Thus the solution above needs less code change.

When you see a white page, it means that an error occurred. You can then take a look in the apache/server error log files to see what error occurred.


thank you so much
i added data on my custom field

Does this process means, that, in general, if we want to add feature to PKP (OMP), we must to change the core code of PKP?

Or we must to develop plugin?

Or we must to extend the core classes in custom plugin?

How to use “the PKP way” to develop that routines?

ihave add the code in registrationform

  <div class="phone">
  		<span class="label">
  			{translate key=""}
  			<span class="required">*</span>
  			<span class="pkp_screen_reader">
  				{translate key="common.required"}
  		<input type="text" name="phone" id="phone" value="{$phone|escape}" maxlength="40" required>

but the phone dosnt show at the user profile (not save to database)

Dear @acahya

Did you check the added field on database or on the user profile?

i had checked both in the database or in the user profile is nothing saved.

i check in the database and user profile too, but nothing is saved there.

Hi @acahya

I had the same problem. There are 3 things to “edit”:

1 - Create the code in the registration form. [you already did]
2 - Add the string ‘phone’ (file: lib/pkp/classes/users/form/ in the array at the line 130(more os less)
3 - With the same file. Add $user->setPhone($this->getData(‘phone’)); Just after the $user = $userDao->newDataObject(); At line 170 (more os less)

Hope it helps!

It can be done from the theme plugin also. Particularly, the theme registration form template can be overridden by simply putting by corresponded path inside plugin’s template folder. RegistrationForm class has hooks in it that allows to add code inside costructor or methods; hooks are inherited from Form class (they can be checked there)

Thanks @rodrigo_snape
its work :smiley:

I am using I did that .But I unable to show this field on registration page.please let me know.

I am using I did that .But I unable to show this field on registration page.please let me know.

Do you have any ideas, is there any list of hook documentation that can be called ?
I checked on this page :

It turns out that this page is not relevant anymore.

Hi @navotera,

I don’t know if there is a list of hooks somewhere.
If talking about forms, hooks are called in methods of the parent class Form, e.g.: pkp-lib/ at e8ec9824d20f4b712cc25ccf35d5ddad365c8447 · pkp/pkp-lib · GitHub

Are you looking for something specific?

Thank you so much @Vitaliy

I just curious how you usually you can get what things that can be hooked to OJS system so I can use it to create any new improvement to my theme.