While using form_builder, I receive the following error:

Notice: Undefined index: value in _webform_render_phone() (line 142 of /home/myusername/public_html/sites/all/modules/webform_phone/webform_phone.components.inc).

To see it in action visit: http://getmart.com/form-builder-example (not my site, just a site that came up when googling the error)

Comments

philsward’s picture

More specifically, I "think" it's happening because the required select field "Country" is not being saved when using form builder.

Also, any other inputs added (such as "add parenthesis" or setting a "separator", fail to retain. When turning off the webform builder UI, all of the phone number settings were live and in-tact but re-enabling webform builder ui, removes all of the settings except for title.

philsward’s picture

I thought I figured out a workaround, but it turns out that saving the webform, clears all of the phone number settings... :(

RadioActiv’s picture

It appears that the form_builder module's support for 3rd party fields is rather buggy. The settings are actually getting saved to the database when you make changes to the field, but form_builder doesn't load the settings from the database into the settings form correctly when you go back to edit/view the settings.

Until form_builder better supports 3rd party fields, I'm going to disable the form_builder support in future releases of the webform_phone module.

philsward’s picture

Sounds good. I hate for it to be disabled but I guess if that's what it takes...

I wasn't sure if it had to do with the form builder or not. Thx for looking into it : )

I'm going to go ahead and use this module with form builder and other than the php error, I don't seem to be having any issues with it. You might consider keeping the feature enabled and just keep this issue open until the form builder is fixed, for those running into the same issue. Just a thought.

quicksketch’s picture

I don't think the Form Builder module is buggy with 3rd-party modules, as there's very little different between the way Webform provides components and the way 3rd-party modules provide components. It should be identical, so I don't think the problem is just because Webform Phone Number is separate.

Form Builder works entirely based off editing FormAPI properties. It looks like when Webform Phone Number renders its field into the normal Webform form, it doesn't pass along any of its own settings. If the settings aren't in the form, then Form Builder won't be able to read them.

In Webform Phone Number's _webform_render_phone() function, you have to set all the individual properties that Form Builder will manipulate, even if these properties have no effect in your own module. However to make your module behave completely inline with what Form Builder wants, you should never reference $element['#component'], and instead reference your own properties.

For example in _webform_render_phone():

  function _webform_render_phone($component, $value = NULL, $filter = TRUE) {
    $form_item = array(
      '#type'             => 'textfield',
      '#default_value'    => $filter ? _webform_filter_values($component['value']) : $component['value'],
      '#attributes'       => $component['extra']['attributes'],
      '#theme_wrappers'   => array( 'webform_element' ),
      '#description'      => $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'],
      '#element_validate' => array( 'webform_validate_phone' ),
      '#maxlength'        => ( $component['extra']['country'] == 'int' ? ( isset( $component['extra']['phone_int_max_length'] ) ? $component['extra']['phone_int_max_length'] : NULL ) : NULL ),
      '#required'         => $component['mandatory'],
      '#size'             => 17,
      '#title'            => $filter ? _webform_filter_xss($component['name']) : $component['name'],
      '#title_display'    => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
      '#weight'           => $component['weight'],
      '#translatable'     => array(
        'title',
        'description'
      ),
    );

You should be setting properties for #phone_country_code, #phone_int_max_length, etc.

And then in webform_validate_phone(), use the #phone_country_code property instead of $element['#webform_component']['extra']['country'].

The overall approach here is to make sure that you have individually editable properties for Form Builder to load and then save. Form Builder doesn't know what to do with the entire #component property because it has too many options. So instead it needs discrete FAPI properties so that each can be edited individually.

RadioActiv’s picture

Status: Active » Needs review

Thanks for the help quicksketch, I had incorrectly assumed that since it worked fine with webform it would be ok with form_builder.

I've committed the changes and they'll be available in 7x.-1.8.

philsward, can you check if the new version causes your error to go away?

quicksketch’s picture

I had incorrectly assumed that since it worked fine with webform it would be ok with form_builder.

Components definitely can be written to "just work" with Form Builder, but it requires a bit of know-how unfortunately. That $element["#component'] property is just so darn tempting... ;)

philsward’s picture

Beautiful! Looks like it is now saving the fields and there's no more error!

Thx to both of you for getting this resolved :)

RadioActiv’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

skriptble’s picture

Version: 7.x-1.6 » 7.x-1.13

I'm having this issue as well, when used dpm the component variable doesn't have the value key, as the error states. Am I missing something?