How to make phone number a required field on user registration? (OJS 3.4.0-9)

Hello,

I am using OJS 3.4.0-9.
I would like to force users to fill in their phone number when creating an account, so that the phone number becomes a mandatory/required field on the registration form (or when adding a new user from the admin/editor side).

At the moment, the phone number field is optional and many users leave it empty.
My questions are:

  1. Is there a built-in setting in OJS 3.4.0-9 to make the phone number required during registration?

  2. If not, what is the recommended way to do this?

    • Editing the registration form template?

    • Overriding the form validation in a custom plugin?

    • Any example code or documentation I can follow?

Any guidance, example, or link to official documentation/tutorial would be very helpful.
Thank you.

Hi @kbh

You can add a Phone Number field to the OJS 3.4 registration form and make it mandatory by updating two core files — one in PHP and one in the Smarty template. The steps are outlined below.

1. Add the Phone Field in registrationForm.tpl

File:

/lib/pkp/templates/frontend/components/registrationForm.tpl

To make it appear in the form, insert the block below just before the <div class="country"> field (approximately line 55) in registrationForm.tpl.

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

This adds the input field to the frontend and makes it required.


2. Update RegistrationForm.inc.php

File:

lib/pkp/classes/user/form/RegistrationForm.inc.php

a) Enable the field to be saved (readInputData / readUserVars)

Locate the method readInputData() (around line 138) and find the readUserVars array.
Add 'phone' to this array (around line 149):

'phone',

b) Save phone value to the User object

Find the method execute() (around line 237). Locate this line:

$user->setEmail($this->getData('email'));

Add the following line near it:

$user->setPhone($this->getData('phone'));

This saves the phone number into the user profile during registration.

1 Like