Hi!

I'm trying to add custom fields to the palette of webform fields. In the end I want to have fields in my palette like "First Name", "Last Name", "ZIP Code", ... that are essentially of type "textfield" or "select" but set label and default values in my module.

I'm struggling to achieve what I want, so far I did the following:

  • I implemented hook_form_builder_types() and added my custom fields e.g. like that:
      $fields['first_name'] = array(
        'title' => t('First name'),
        'properties' => array(
          'title',
          'description',
          'field_prefix',
          'field_suffix',
          'default_value',
          'required',
          'size',
        ),
        'default' => array(
          '#title' => t('First name'),
          '#type' => 'textfield',
        ),
      );
    
  • I implemented hook_form_builder_types_alter and unset the default field types (like "grid" etc) in order to only have my custom fields displayed.

This approach has the small problem that although I can drag & drop my custom fields into the webform, when I save them then I'm getting error messages of undefined indexes of "first_name" etc.
My guess is, the webform module doesn't know about a "first_name" type. But I don't know how I can tell webform that it should treat it like a "textfield".

Can anyone give me some hints how I can achieve what I want?

Comments

quicksketch’s picture

It sounds like you first need to write a component for Webform using Webform's hooks. For simplicity, it may be better if you temporarily disable Form Builder and write the component directly against Webform.

The Form Builder Webform Integration module will do most of the necessary Form Builder work for you if you include a _form_builder_webform_form_builder_map_[component_type]() function in your component include file. Read the webform.api.php file included with Webform for more information about creating custom Webform components.

matthias_mo’s picture

Status: Active » Closed (fixed)

I found a solution to this. It's not the most elegant way but it does the job.

quicksketch, I didn't want to re-implement an existing field like e.g. the textfield, all I wanted to do was use the existing field, change some parameters and offer it in the palette as some custom field to my users.

In case anyone is interested, I wrote a blog post how to do it, comments are welcome of course.

This issue can be closed from my side.