Skip to:
Content

BuddyPress.org

Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#7845 closed defect (bug) (fixed)

User registration fails if multi-option multi-select or checkbox involved

Reported by: DJPaul Owned by: r-a-y
Milestone: 3.1.0 Priority: normal
Severity: normal Version: 3.0.0
Component: Registration Keywords: has-patch commit
Cc:

Description

This is showing up on the forums:

That second link by @rhwentworth has a good write-up:

In BuddyPress 3.0.0, there is a bug insofar as if a registration form is submitted and a multi-select or checkbox is involved, and multiple options are present, the registration fails with a run-time error as follows:
.
Warning: trim() expects parameter 1 to be string, array given in /home8/fromchao/public_html/buddypress/wp-content/plugins/buddypress/bp-members/screens/register.php on line 93
.
In my local copy, I patched line 92 to add a check to see if an what was returned is an array, and this eliminated the error for me. Might even be the right fix, as the individual returns in an array shouldn't need trimming.
This problem occurred on a dev test site running WordPress 4.9.6. But, the problem and its cause seem pretty obvious, and not a function of WordPress itself. Just needs to be fixed in the official distribution.

if ( isset( $_POST[ 'field_' . $field_id ] ) and !is_array( $_POST[ 'field_' . $field_id ] ) )  // FIXED!!
$_POST[ 'field_' . $field_id ] = trim( $_POST[ 'field_' . $field_id ] );

Attachments (1)

7845.01.patch (824 bytes) - added by r-a-y 14 months ago.

Download all attachments as: .zip

Change History (7)

#1 @r-a-y
14 months ago

See #7671 where this was introduced.

Do we want to run trim() through the multi-option posted array or just introduce the simple is_array() fix as listed in the ticket description?

#2 @DJPaul
14 months ago

  • Milestone changed from 3.0.1 to 3.1.0

Milestone renamed

@r-a-y
14 months ago

#3 @r-a-y
14 months ago

  • Keywords has-patch added
  • Version set to 3.0.0

01.patch runs trim() through post fields that are arrays as well.

If we are only worried about text fields, then we can just go with the simple fix listed in the ticket description.

#4 @DJPaul
14 months ago

  • Keywords commit added

Looks fine thank you for working on this

#5 @r-a-y
14 months ago

  • Owner set to r-a-y
  • Resolution set to fixed
  • Status changed from new to closed

In 12150:

Registration: Trim POST fields for multi-select and checkbox options.

The change made in #7671 to trim registration POST fields broke profile
fields that contained multi-select or checkbox options. This is because
these fields use arrays. To address this, we now also trim array POST
fields.

See #7671.

Fixes #7845 (3.x branch).

#6 @r-a-y
14 months ago

In 12151:

Registration: Trim POST fields for multi-select and checkbox options.

The change made in #7671 to trim registration POST fields broke profile
fields that contained multi-select or checkbox options. This is because
these fields use arrays. To address this, we now also trim array POST
fields.

Fixes #7845 (trunk).

Note: See TracTickets for help on using tickets.