Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Netzdepp

    (@netzdepp)

    Can nobody help?

    Ain’t there any options how I can use a dropdown or a radio button with multiple selection?

    Plugin Author Chad Butler

    (@cbutlerjr)

    There is not a radio button or multiselect option native in the plugin at this time (although I am working on redesigning the fields and forms during the 3.x lifecycle – I expect 3.1 or 3.2 to support additional form input types).

    Generally, the way to approach it currently is to add the field as a regular text input field (essentially as a placeholder) and then use the wpmem_register_form_rows filter to change the HTML for the field.

    I haven’t tried it, and it might take some additional processing for managing the data, but the simplest for a multiple select dropdown would be to create it as a dropdown and then use that same filter to add the “multiple” attribute and make the name attribute an array (to pass all selected items):

    add_filter('wpmem_register_form_rows', 'my_form_rows');
    function my_form_rows($rows){
    
    	// use str_replace to add in "multiple" to the select tag and change
    	// the name attribute to pass an array where 'test_field' is the
    	// option name of the field being filtered
    	$old = '<select name="test_field"';
    	$new = '<select multiple name="test_field[]"';
    	$str = $rows['test_field']['field'];
    	$rows['test_field']['field'] = str_replace( $old, $new, $str );
    
    	return $rows;
    }

    To handle the posted data as a single string, I would use the wpmem_register_data filter to implode the posted test_field[] array into comma separated values:

    add_filter('wpmem_register_data', 'my_form_rows_post');
    function my_form_rows_post( $fields ) {
    	if ( isset( $_POST['test_field'] ) ) {
    		$fields['test_field'] = '"'.implode( '","', $_POST['test_field'] ).'"';
    	}
    	return $fields;
    }

    There would probably need to be some additional considerations for displaying the data on the admin side user profile, but this would at least capture the data.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Radio Buttons (Multiple Options)’ is closed to new replies.