When using he form API setting the default value to the value of the element in case of re-displaying the form using values stored in session or elsewhere causes the error:

Warning: html_entity_decode() expects parameter 1 to be string, array given in select_or_other_multi_array_key_exists() (line 286 of ...sites/all/modules/select_or_other/select_or_other.module).

Notice: Array to string conversion in select_or_other_element_process() (line 164 of ...sites/all/modules/select_or_other/select_or_other.module).

So you cannot use the submitted value of the element as the default value or what form does that need to be in?

array (
'select' =>
array (
'value_1' => 'value_1'',
),
'other' => 'test',
)

CommentFileSizeAuthor
#2 db.png9.07 KBendless_wander
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

haydeniv’s picture

Status: Active » Postponed (maintainer needs more info)

Can you post the code you are using to set the default value.

endless_wander’s picture

FileSize
9.07 KB

I'm having a similar issue when using the Form API to build a "select_or_other" field.

For me, it's not related to using the default value or not. What happens is that the selected options in the $submission array for a Webform are not able to be read.

Here's what I mean:

My abbreviated code for the form itself:

$form['submitted']['submit_this_reflection_to'] = array(
	'#title' => t('Submit this Reflection to'),
	'#title_display' => 'before',
	'#required' => 1,
	'#weight' => 100,
	'#options' => array(
		$agency_admin->mail => $agency_admin->mail,
		'1@one.com' => '1@one.com',
		'2@two.com' => '2@two.com'
		),
	'#default_value' => '',
	'#type' => 'select_or_other',
	'#other' => t('Other Email'),
	'#other_title' => t('Submit this Reflection to Other Email'),
	'#select_type' => 'checkboxes',
);

The important line here is the #options being set. For me, I'm using the Form API so I can insert a variable as one of the options while allowing the users to set an option themselves.

With all options selected and no "other" element added, the $form_state['values']['submitted'] used to save to the db looks like this:

$submission->data => Array
    [4] => Array
        (
            [0] => Array
                (
                    [1@one.com] => 1@one.com
                    [2@two.com] => 2@two.com
                    [agencya_admin@test.com] => agencya_admin@test.com
                    [select_or_other] => 0
                )

The problem seems to be that the $submission->data[4][0] is made up of more arrays. When I try to use the $submission object that is created by retrieving the data from the db, all the email addresses are just blank arrays.

Specifically, each value in $submission->data[4]['value'][0] just prints out as Array() rather than as the email address.

In the db, the row for the submission looks like the attached.

Any ideas? Is this expected?

haydeniv’s picture

Did you try setting
'#multiple' => TRUE,
See: http://drupal.org/node/1158654

legolasbo’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Closing because this issue has been inactive for over a year. Please reopen if this is currently an issue for you and provide steps to reproduce.