The following notice happens to us when using Select or Other with Webform and Form Builder.

Notice: Undefined index: #default_value in webform_expand_select_or_other()

Will post a patch asap.

Comments

markus_petrux’s picture

Status: Active » Needs review
StatusFileSize
new821 bytes
danchadwick’s picture

Status: Needs review » Needs work

This doesn't sound right to me. Every element should have a #default_value. I think we need to fix this at the source, which is probably not within webform itself.

markus_petrux’s picture

I think the problem is Select or Other module defines this as NULL in select_or_other_element_info(), which is left like that if the user does not set a default explicitly.

The PHP notice happens when trying to edit the Webform properties with Form Builder.

Any idea on which is the best place to address this issue?

PS: Thanks for the quick reply!

danchadwick’s picture

Project: Webform » Form Builder
Version: 7.x-4.x-dev » 7.x-1.x-dev
Component: Code » Form Builder Core

Moving this to the Form Builder queue. Please feel free to move back here if indeed there is an issue in webform itself.

markus_petrux’s picture

hmm... I think it is possible that #default_value is not defined at all. For example, for radios elements where the webform editor needs to force the end user to choose an option.

So in this scenario, it makes sense to check if it is set before seeing if it's an array.

torotil’s picture

Project: Form Builder » Webform
Version: 7.x-1.x-dev » 7.x-4.x-dev
Component: Form Builder Core » Code

_webform_render_select() doesn't guarantee that #default_value is set (value==NULL and multiple=FALSE) and webform_expand_select_or_other() does rely on it being set. That's clearly a bug in webform.

BTW the default_value-logic in _webform_render_select() is so unreadable that it warrants a refactoring anyway.

  • DanChadwick committed e47f3f8 on 7.x-4.x
    Issue #2396083 by DanChadwick: Notice: Undefined index: #default_value...
  • DanChadwick committed 5575ef5 on 8.x-4.x
    Issue #2396083 by DanChadwick: Notice: Undefined index: #default_value...
danchadwick’s picture

Version: 7.x-4.x-dev » 8.x-4.x-dev
Status: Needs work » Fixed
StatusFileSize
new3.02 KB

@torotil -- Something is still wrong with Form Builder. The #default_value is filled in when form_builder() (the form.inc core function, not the contrib module) calls element_info(). select_or_other_element_info() sets the #default_value to NULL for select_or_other elements.

That said, I think it is better if the default is always set. The code was hideously redundant, so I simplified it. I have tested every case I can think of and hope am pretty sure that I haven't created any regressions.

Committed to 7.x-4.x and 8.x.

torotil’s picture

Thanks for taking the time to simplify the code. I might include that in 7.x-3.x too. Fixing this in form_builder would have been a lot harder.

torotil’s picture

Here is the backport to 7.x-3.x.

  • torotil committed b4ebc8c on 7.x-3.x authored by DanChadwick
    Issue #2396083 by DanChadwick, torotil: Notice: Undefined index: #...
danchadwick’s picture

Version: 8.x-4.x-dev » 7.x-4.x-dev

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.