Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select field renders option values same as the label if the first option has a numeric value. #225

Open
3 tasks done
ipokkel opened this issue Dec 6, 2021 · 0 comments
Open
3 tasks done

Comments

@ipokkel
Copy link
Member

ipokkel commented Dec 6, 2021

Describe the bug
When creating a select field and the first value for the select options is numerical (string or integer) the rendered HTML returns the option label instead of the set option value as the value.

To Reproduce

  1. Create code for 2 multiple select fields, setting the first field's select option values all numerical and the for the second field set the first option to a string containing alphanumerical characters.

For Example:

function my_pmprorh_init_custom_registration_fields_1638785793517() {
	// don't break if Register Helper is not loaded
	if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
		return false;
	}

	// define the fields
	$fields = array();

	/*
		This field will only appear when checking out
		for the membership levels with level ID 1, 3, or 5.
	*/
	$fields[] = new PMProRH_Field(
		'select_example', // input field name, used as meta key
		'select',         // field type
		array(
			'label'          => 'Select example', // display custom label, if not used field name will be used
			'profile'        => true, // show on profile
			'memberslistcsv' => true, // include when using export members to csv
			'addmember'      => true, // include when using add member from admin
			'multiple' => true,
			'options'        => array(
				'1'  => 'Option One',
				'2'  => 'Option Two',
				'3'  => 'Option Three',
			),
		)
	);

	/*
	Rendered HTML:
	<select id="select_example" name="select_example[]" class="input " multiple="multiple">
		<option value="Option One">Option One</option>
		<option value="Option Two">Option Two</option>
		<option value="Option Three">Option Three</option>
	</select>
	*/
	$fields[] = new PMProRH_Field(
		'select_example_two', // input field name, used as meta key
		'select',         // field type
		array(
			'label'          => 'Select example two', // display custom label, if not used field name will be used
			'profile'        => true, // show on profile
			'memberslistcsv' => true, // include when using export members to csv
			'addmember'      => true, // include when using add member from admin
			'multiple' => true,
			'options'        => array(
				'option_1'  => 'Option One',
				'2'  => 'Option Two',
				'3'  => 'Option Three',
			),
		)
	);
	/*
	Rendered HTML:
	<select id="select_example_two" name="select_example_two[]" class="input " multiple="multiple">
		<option value="option_1">Option One</option>
		<option value="2">Option Two</option>
		<option value="3">Option Three</option>
	</select>
	*/

	foreach ( $fields as $field ) {
		pmprorh_add_registration_field(
			'checkout_boxes', // location on checkout page
			$field     // PMProRH_Field object
		);
	}
}
add_action( 'init', 'my_pmprorh_init_custom_registration_fields_1638785793517' );
  1. Navigate to checkout page and inspect rendered HTML for these fields.

Screenshot 1

211206-1638786962
select_example Note the incorrect values for each option

Screenshot 2

211206-1638786989
select_example_two Note the correct values for each option.

Expected behavior
Values for each option of a select field rendered in HTML should be the same as in the field creation code snippet.

Isolating the problem (mark completed items with an [x]):

  • I have deactivated other plugins and confirmed this bug occurs when only Paid Memberships Pro plugin is active.
  • This bug happens with a default WordPress theme active, or Memberlite.
  • I can reproduce this bug consistently using the steps above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant