WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#28207 closed defect (bug) (duplicate)

$extra_fields of request_filesystem_credentials does not accept array's

Reported by: bassjobsen Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9.1
Component: Filesystem API Keywords:
Focuses: Cc:

Description

If my form for instance contains:

<input type="text" name="test[]">
<input type="text" name="test[]">

i can not add test to $extra_fields

possible solution:

/*foreach ( (array) $extra_fields as $field ) {
	if ( isset( $_POST[ $field ] ) )
		echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( wp_unslash( $_POST[ $field ] ) ) . '" />';
}*/
foreach ( (array) $extra_fields as $field ) {
	if ( isset( $_POST[ $field ] ) )
	{
		
		if(is_array($_POST[ $field ]))
		{
			foreach($_POST[ $field ] as $key=>$value)
			{
				echo '<input type="hidden" name="' . esc_attr( $field ) . '[' .esc_attr( $key ). ']" value="' . esc_attr( wp_unslash(  $value ) ) . '" />';
			}
		}
		else 
		{
		echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( wp_unslash( $_POST[ $field ] ) ) . '" />';
		}
	}	
}

Change History (2)

#1 @bassjobsen
6 years ago

For multidimensional arrays some recursion will be needed too:

 function with_recursion($value,$string)
{
	foreach($value as $key=>$value) {
				if(is_array($value)) {with_recursion($value, $string . '[' . $key . ']');}
				else 
				{
				echo $string.'[' . $key . ']" value="' .  $value  . '" />';
			    }
    }	
}	
foreach ( (array) $extra_fields as $field ) {
	if ( isset( $_POST[ $field ] ) )
	{
		
		if(is_array($_POST[ $field ]))
		{                              
			foreach($_POST[ $field ] as $key=>$value)
			{
				
				if(is_array($value)) {with_recursion($value, '<input type="text" name="' . esc_attr($field). '[' . esc_attr($key). ']');}
				else 
				{
				echo '<input type="hidden" name="' . esc_attr($field). '[' . esc_attr( $key ). ']" value="' .  esc_attr( wp_unslash($value))  . '" />';
			    }
			}
		}
		else 
		{
		echo '<input type="hidden" name="' .  esc_attr($field)  . '" value="' . esc_attr( wp_unslash( $_POST[ $field ]))  . '" />';
		}
	}	
}

#2 @wonderboymusic
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #19643.

Note: See TracTickets for help on using tickets.