Mailing address as a required field in OCS

Hi,

We are running OCS 2.3.6.

We need the mailing address to always be a required field.

I tried adding

$this->addCheck(new FormValidator($this, 'mailingAddress', 'required', 'user.profile.form.mailingAddressRequired'));

to

classes/user/form/CreateAccountForm.inc.php

as this is included in

classes/registration/UserRegistrationForm.inc.php

and the mailing address is required if you want to register for a conference and have not yet created an account.

Also, adding this line seems to have worked on OJS:

Unfortunately, it has no effect in our OCS. Did I miss something obvious? Any help would be appreciated.

Thanks in advance.

Hi @Katja,

Have you tried submitting the form? Those changes should make the field required upon submission. If you’re expecting the “required” * to appear beside the field, that’ll take a template change as well.

Regards,
Alec Smecher
Public Knowledge Project Team

Hi Alec,

I can submit the form without any errors and create an account with an empty mailing address field. I don’t have to fill in an address before saving the changes to my profile either.

Since I am not a programmer, I might have overlooked details, like the order in which to list these form validator lines or something.

I have not touched the templates yet, so I did not expect the asterix to appear beside the label. I wanted to see, if it works first.

Regards, Katja

Hi @Katja,

Can you describe the modifications in more detail, e.g. where exactly you made changes?

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @Alec,

sorry for the delay. I only ever added the line listed above to

classes/user/form/CreateAccountForm.inc.php

to the contructor function “CreateAccountForm()”

at section “New user – check required profile fields” line 55 downwards

between the checks for affiliation and email.

    function CreateAccountForm() {
		parent::Form('user/createAccount.tpl');

		$this->existingUser = Request::getUserVar('existingUser') ? 1 : 0;

		import('captcha.CaptchaManager');
		$captchaManager = new CaptchaManager();
		$this->captchaEnabled = ($captchaManager->isEnabled() && Config::getVar('captcha', 'captcha_on_register'))?true:false;

		// Validation checks for this form
		$this->addCheck(new FormValidator($this, 'username', 'required', 'user.profile.form.usernameRequired'));
		$this->addCheck(new FormValidator($this, 'password', 'required', 'user.profile.form.passwordRequired'));

		if ($this->existingUser) {
			// Existing user -- check login
			$this->addCheck(new FormValidatorCustom($this, 'username', 'required', 'user.login.loginError', create_function('$username,$form', 'return Validation::checkCredentials($form->getData(\'username\'), $form->getData(\'password\'));'), array(&$this)));
		} else {
			// New user -- check required profile fields
			$site =& Request::getSite();

			$this->addCheck(new FormValidatorCustom($this, 'username', 'required', 'user.account.form.usernameExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByUsername'), array(), true));
			$this->addCheck(new FormValidatorAlphaNum($this, 'username', 'required', 'user.account.form.usernameAlphaNumeric'));
			$this->addCheck(new FormValidatorLength($this, 'password', 'required', 'user.account.form.passwordLengthTooShort', '>=', $site->getMinPasswordLength()));
			$this->addCheck(new FormValidatorCustom($this, 'password', 'required', 'user.account.form.passwordsDoNotMatch', create_function('$password,$form', 'return $password == $form->getData(\'password2\');'), array(&$this)));
			$this->addCheck(new FormValidator($this, 'firstName', 'required', 'user.profile.form.firstNameRequired'));
			$this->addCheck(new FormValidator($this, 'lastName', 'required', 'user.profile.form.lastNameRequired'));
			$this->addCheck(new FormValidatorUrl($this, 'userUrl', 'optional', 'user.profile.form.urlInvalid'));
			$this->addCheck(new FormValidatorEmail($this, 'email', 'required', 'user.profile.form.emailRequired'));
			$this->addCheck(new FormValidator($this, 'affiliation', 'required', 'user.profile.form.affiliationRequired'));
			// Test: additional check for mailing address field , 2017-01-11, kti
			$this->addCheck(new FormValidator($this, 'mailingAddress', 'required', 'user.profile.form.mailingAddressRequired'));
			$this->addCheck(new FormValidatorCustom($this, 'email', 'required', 'user.account.form.emailExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByEmail'), array(), true));
			if ($this->captchaEnabled) {
				$this->addCheck(new FormValidatorCaptcha($this, 'captcha', 'captchaId', 'common.captchaField.badCaptcha'));
			}

			$authDao =& DAORegistry::getDAO('AuthSourceDAO');
			$this->defaultAuth =& $authDao->getDefaultPlugin();
			if (isset($this->defaultAuth)) {
				$this->addCheck(new FormValidatorCustom($this, 'username', 'required', 'user.account.form.usernameExists', create_function('$username,$form,$auth', 'return (!$auth->userExists($username) || $auth->authenticate($username, $form->getData(\'password\')));'), array(&$this, $this->defaultAuth)));
			}
		}

		$this->addCheck(new FormValidatorPost($this));

I did not change any other files.

Hi @Katja,

That looks right to me, at a glance – just to check, where are you expecting this change to take place? (Can you post the URL to the form you’re testing with? Feel free to obscure the domain name, I just need the part after the index.php.)

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @Alec,

I expected the change here:

{IP and path to OCS}/index.php/test/test2015/user/createAccount#formErrors

At least, that’s what I get if I deliberately leave out required information.

I thought, that maybe the error just doesn’t show here, but wouldn’t the system let us know somehow, that it could not properly set up the account?

Hi @Katja,

Ah, reviewing that form I think the issue is that the mailing address field is a TinyMCE (rich text) field, so it’s possible that the field is submitting an empty element, which is satisfying the form validator. I’d suggest using FormValidatorCustom to create a custom validator that checks that content is actually present – e.g. something passing the content through both strip_tags and trim to see if the result is empty.

Regards,
Alec Smecher
Public Knowledge Project Team

Hi Alec,

thanks for the hint! I will try a custom validator and let you know if it works.

Regards, Katja

Alec,

I am very sorry for the confusion. It actually works as expected with the standard form validator if you edit in the right subdirectories of your machine.

Anyway, thanks for your input, I will bear it in mind.

Best Regards,

Katja

Hi @Katja,

It sounds like this is resolved – thanks for following up!

Regards,
Alec Smecher
Public Knowledge Project Team