Selected the optional form field for user registration.

http://d.pr/i/178Sn

When a user attempts to register, they receive the error 'No phone number provided.'

I tried turning off the validation module and incurred the same problem.

If you need more information, please let me know.

Comments

nDigitHQ’s picture

Version: 7.x-1.x-dev » 7.x-1.0-alpha1
nDigitHQ’s picture

Component: SMS User » Core Framework
nDigitHQ’s picture

Component: Core Framework » SMS User
nDigitHQ’s picture

Updated the issue. Problem is with both the dev and alpha branches.

The function sms_user_validate_number_element doesn't check to see if the field is optional. It passes it to the validation no matter what.

nDigitHQ’s picture

Was able to patch it without git. Could you please roll this into the next release?

function sms_user_validate_number_element($element, &$form_state, $form) {
  $number = $element['#value'];
  
  if (variable_get('sms_user_registration_form') === 2) {
	if ($error = sms_validate_number($number)) {
	  foreach ($error as $lerror) {
		form_error($element, $lerror);
	  }
	}
	elseif (sms_user_get_uid($number)) {
	  form_error($element, t('This phone number is already registered to another user.'));
	}
  }
}
almaudoh’s picture

Issue tags: +Needs tests

Need to write a failing test for this bug first.

almaudoh’s picture

Version: 7.x-1.0-alpha1 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.96 KB

Uploaded failing test...

Status: Needs review » Needs work

The last submitted patch, 7: optional_field_on-2509098-7-FAIL.patch, failed testing.

almaudoh’s picture

Status: Needs work » Needs review
StatusFileSize
new2.62 KB
new681 bytes
function sms_user_validate_number_element($element, &$form_state, $form) {
  $number = $element['#value'];
  
  if (variable_get('sms_user_registration_form') === 2) {
	if ($error = sms_validate_number($number)) {
	  foreach ($error as $lerror) {
		form_error($element, $lerror);
	  }
	}
	elseif (sms_user_get_uid($number)) {
	  form_error($element, t('This phone number is already registered to another user.'));
	}
  }
}

This patch may fix the bug, but also introduces another one - the validation will no more work when you supply a mobile number in the optional textbox.

Attached patch fixes it where the problem lies - in the sms_validate_number() function.

Tests also pass.

  • almaudoh committed ad96b6a on 7.x-1.x
    Issue #2509098 by almaudoh, nDigitHQ: "Optional" field on registration...
almaudoh’s picture

Status: Needs review » Fixed

Committed / pushed to 7.x-1.x

almaudoh’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Fixed » Patch (to be ported)
Issue tags: -Needs tests

Need to port this to 8.x-1.x branch.

almaudoh’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new2.31 KB
new3.02 KB

D8 patch...

The last submitted patch, 13: optional_field_on-2509098-13-FAIL.patch, failed testing.

  • almaudoh committed fe94d11 on 8.x-1.x
    Issue #2509098 by almaudoh, nDigitHQ: "Optional" field on registration...
almaudoh’s picture

Status: Needs review » Fixed

Committed and pushed D8 port to 8.x-1.x

nDigitHQ’s picture

Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.